/* * MyPlayer.java * * Created: * By: * * Description: Player methods for Tic-Tac-Toe. * For Assignment 5, CS111 A1, Spring 2005. */ package program5; public class MyPlayer { /** Creates a new instance of MyPlayer */ public MyPlayer() { } /* This method selects the next move for player for the given 3x3 board. It returns a 1-D array that gives the {row,column} location selected for the next move. If there is no move available (board is full), then the method returns {-1,-1} */ public static int[] selectMove(int[][] board, int player){ int[] m = {-1,-1}; /* You write this method */ /* remove the code below when you write your method! It picks first empty spot (not a winning strategy) */ for(int i=0;i<3;++i) for(int j=0;j<3;++j) if(board[i][j]==TicTacToe.EMPTY){ m[0] = i; m[1] = j; return m; } return m; } /* This method searches the tic-tac-toe board to see if there is a winning move available for player. In other words, the method looks for a row, column, or diagonal on the current board where there is an open spot, and the other two spots are already taken by player. The board is a 3x3 array. This method returns an array {row,column} of the winning move for player if there is one. If there is no winning move, then the method returns {-1,-1}.*/ public static int[] findWinningMove(int[][] board, int player){ int[] m = {-1,-1}; /* You write this method */ return m; } }