• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stymied on tic tac toe project

 
John Snoddy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple tic tac toe project due (last week actually) and am at a loss in finally finishing it and the current errors. Any help would be greatly appreciated!

//December 01, 2008
//CIS 130 Lab9_TicTacToe1

import java.io.*;
import java.util.*;

public class Lab9_TicTacToe1
{
public static void main (String args [])
{
int moves, curr_player, cell, winner;

Scanner kb=new Scanner(System.in);

//string variable for names of players (player1 and player2)
moves=0;
cell=0;

int board[]=new int[9];

while((moves<9) && (winner == 0))
{
//input cell - if the cell is unoccupied (check value for 0)
{
moves++;

//set the br[cell] = curr_player;
//use switch statement to determine if that move makes the user a winner

switch(cell)
{
case 0:
if((br[0] == curr_player) && (br[1] == curr_player) && (br[2]==curr_player))
System.out.println("The winner is " + curr_player);
break;

case 1:
if((br[3] == curr_player) && (br[4] == curr_player) && (br[5]==curr_player))
System.out.println("The winner is " + curr_player);
break;

case 2:
if((br[6] == curr_player) && (br[7] == curr_player) && (br[8]==curr_player))
System.out.println("The winner is " + curr_player);
break;

case 3:
if((br[0] == curr_player) && (br[3] == curr_player) && (br[6]==curr_player))
System.out.println("The winner is " + curr_player);
break;

case 4:
if((br[1] == curr_player) && (br[4] == curr_player) && (br[7]==curr_player))
System.out.println("The winner is " + curr_player);
break;

case 5:
if((br[2] == curr_player) && (br[5] == curr_player) && (br[8]==curr_player))
System.out.println("The winner is " + curr_player);
break;

case 6:
if((br[0] == curr_player) && (br[4] == curr_player) && (br[8]==curr_player))
System.out.println("The winner is " + curr_player);
break;

case 7:
if((br[2] == curr_player) && (br[4] == curr_player) && (br[6]==curr_player))
System.out.println("The winner is " + curr_player);
break;

//similarly check other possible winning combination including 0 cell
}

//After getting out of switch display the board

if (winner == 0)
{
if(player == 1)
System.out.println(player = 2);

else
System.out.println(player = 1);
}
moves++;
}
}//end of for checking valid move

else
System.out.println("Invalid move.");
}//end while

if(winner != 0)
{
if(curr_player==1)
System.out.println(player2 + " is the winner.");
}
else
System.out.println("Game ended without a winner.");
}
}
 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple tic tac toe project due (last week actually) and am at a loss in finally finishing it and the current errors.


Well, what are these errors that you are encountering? Are they compile errors? runtime errors?

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic