Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

oxo game

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Report post to moderator
the programme below compiles but when i run it nothing happens



/**
A 3 x 3 board for naughts and crossses
*/
public class OXOGame
{
/**
Constructs an empty board.
*/
public OXOGame()
{

board = new char[ROWS][COLUMNS];

// fill with spaces
for (int i = 0; i < ROWS; i++)
for (int j = 0; j < COLUMNS; j++)
board[i][j] = ' ';
}

/**
Sets a field in the board. The field must be unoccupied.
@param i the row index
@param j the column index
@param player the player ('x' or 'o')
*/
public boolean set(int i, int j, char player)
{
if (board[i][j] != ' ')
return false;
board[i][j] = player;
return true;
}

/**
Creates a string representation of the board such as
|x o|
| x |
| o|
@return the string representation
*/
public String toString()
{
String r = "";
for (int i = 0; i < ROWS; i++)
{
r = r + "|";
for (int j = 0; j < COLUMNS; j++)
r = r + board[i][j];
r = r + "|\n";
}
return r;
}
private char[][] board;
private static final int ROWS = 3;
private static final int COLUMNS = 3;
}
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Just closing this one, since it is a duplicate post of your Tic-Tac-Toe post.

Mark
 
You got style baby! More than this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!