• Post Reply 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Stymied on tic tac toe project

 
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.");
}
}
 
author
Posts: 23840
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
I found a beautiful pie. And a tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!