The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
i need help in compliting this code it's a tictactoe game using java :
Â
import java.util.Scanner;
import java.io.FileReader;
import java.io.BufferedReader;
Â
public class TicTacToeGame{
 /** symbol for X */
 public static final Character ex = 'X';
 Â
 /** symbol for O */
 public static final Character oh = 'O';
Â
 /** symbol for empty grid element */
 public static final Character empty = ' ';
 Â
 /** board is the grid that the game is played on;Â
  * each element must be one of ex, oh or empty*/
 public static Character[][] board;
 Â
 Â
 /** rows is the number of rows (N) in the game board */
 public static int rows;
  Â
 /** columns is the number of columns (M) in the game board */
 public static int columns;
 Â
 /** win_condition is the value of K, the winning condition of the game */
 public static int win_condition;Â
 Â
 /** specifies if the game is 1p (human-human) or 2p (human-computer) */
 public static boolean human_human_game;
 Â
 Â
 /** Checks for a win based on the last symbol played in the game
  *Â
  * It is assumed that the position specified by the last_row_played
  * and last_column_played is valid and that the symbol in the board
  * at that position is not empty. (It must be <em>ex</em> or <em>oh</em>)
  *Â
  * @param last_row_played is the row of the last symbol played
  * @param last_column_played is the column of the last symbol played
  * @return the length of the winning row/column/diagonal of symbolsÂ
  * if the last move is a winning move, or -1 if the last move is notÂ
  * a winning move.
  */
 public static int win(int last_row_played, int last_column_played){
  // add your code and change the return value
  return -2;
 }
 Â
 /** main method to run the gameÂ
  *Â
  * @param args optional command line arguments toÂ
  * specify if the game is 1p (human-computer) or
  * 2p (human-human). Expect the string "2p" if any
  * command line argument is given.
  */
 public static void main(String[] args){
  Â
  /*------------------------------------------
   * handle command line arguments if any  Â
   * to determine if the game is human-humanÂ
   * or human-computer           Â
   *------------------------------------------*/
  if( args.length > 0){
   /* there are commend line arguments present */
   Â
   // add your code here
   Â
  }else{
   /* there are no command line argument present */
   Â
   // add your code here
   Â
  }
  Â
  /*------------------------------------
   * read N-M-K data from init file Â
   * N = rows            Â
   * M = columns          Â
   * K = win_condition       Â
   *------------------------------------*/
  Â
  /*-------------------------------------
   *-------------------------------------
   * BEGIN : Do NOT change the code here
   *-------------------------------------*/
  BufferedReader file_input;
  FileReader  file;
  String    file_name = "init";Â
  String    line;
  Â
  try{
   file = new FileReader(file_name);
   file_input = new BufferedReader(file);
   Â
   line = file_input.readLine();
   rows = Integer.parseInt(line);
   Â
   line = file_input.readLine();
   columns = Integer.parseInt(line);
   Â
   line = file_input.readLine();
   win_condition = Integer.parseInt(line);
   Â
   /* always close your files you are done with them! */
   file_input.close();
   Â
  }catch(Exception e){
   /* somethine went wrong! */
   System.err.println("Failure to read data from init file properly");
   System.err.println(e);
   System.err.println("Program ending");
   return;
  }
Â
  Â
  /*-------------------------------------
   * END : Do NOT change the code here
   *-------------------------------------Â
   *-------------------------------------*/
Â
  Â
  /* create and initialize the game board */
  Â
  /* allocate memory for the board array */
  board = new Character[rows][columns];
  Â
  // add code to initialize all elements to empty
  Â
  Â
  /* code to drive the game */
  Â
  // add your code here
  Â
  Â
 }
 Â
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly