Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @(#)XOTest.java
- *
- *
- * @author
- * @version 1.00 2011/12/16
- */
- public class XOTest {
- //Board size
- static int BOARD_SIZE=3;
- //Draw board function
- public static void printBoard(char[][] board){
- for(int i=0;i<BOARD_SIZE;i++){
- System.out.println("-------");
- String s="";
- for(int j=0;j<BOARD_SIZE;j++){
- s+="|"+board[i][j];
- }
- s+="|";
- System.out.println(s);
- }
- System.out.println("-------");
- }
- //Check if X is the winner
- public static void checkWinnerX(char[][] board){
- //Winning condition
- boolean winX=false;
- for(int i=1;i<BOARD_SIZE;i++){
- for(int j=1;j<BOARD_SIZE;j++){
- //טור
- if(board[BOARD_SIZE-i][j]=='X'){
- winX=true;
- }
- //שורה
- if(board[i][BOARD_SIZE-j]=='X'){
- winX=true;
- }
- //אלכסון
- if(board[BOARD_SIZE-i][BOARD_SIZE-j]=='X'){
- winX=true;
- }
- }
- }
- if(winX){
- System.out.println("X wins!");
- }
- }
- public static void main(String[] args) {
- //Test array
- char[][] board={{'X','O','O'},{'O','X','O'},{'O','O','O'}};
- printBoard(board);
- checkWinnerX(board);
- }
- }
Add Comment
Please, Sign In to add comment