Beispiel #1
0
        // returns list of valid positions to consider, or null if none are found
        private List <int[]> GetValidMoves(char color, char[,] boardState)
        {
            // list of valid moves to return
            List <int[]> validMoves = new List <int[]>();

            // search each square of board, if a legal move is found return true
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (AttachedGame.CheckMove(new int[] { i, j }, color, boardState) != null)
                    {
                        validMoves.Add(new int[] { i, j });
                    }
                }
            }

            // if any valid moves are found, return list, else return null
            if (validMoves.Count > 0)
            {
                return(validMoves);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        // apply the supplied move to the supplied copy of the board
        private void ApplyMove(int[] move, char[,] boardCopy, char turnColor)
        {
            List <int[]> positionsToUpdate = AttachedGame.CheckMove(move, turnColor, boardCopy);

            positionsToUpdate.ForEach(position =>
            {
                boardCopy[position[0], position[1]] = turnColor;
            });
        }
Beispiel #3
0
 // returns true if there are no legal moves for either black or white
 private bool GameOver(char[,] boardState)
 {
     return(!AttachedGame.HasLegalMoves('@', boardState) && !AttachedGame.HasLegalMoves('O', boardState));
 }