public bool checkForWin(Player.Color color) { var moves = new List <Pair>(); var diskQ = new Queue <Disk>(); if (color == Player.Color.White) { diskQ.Enqueue(new Disk(0, 0, Player.Color.White)); moves.Add(new Pair(0, 0)); if (whiteDiskCount < 9) { return(false); } } else { diskQ.Enqueue(new Disk(0, size - 1, Player.Color.Black)); moves.Add(new Pair(0, size - 1)); if (blackDiskCount < 9) { return(false); } } while (diskQ.Count != 0) { Disk currentDisk = diskQ.Dequeue(); if (currentDisk.pos.row > 0) { // check north if (board[currentDisk.pos.row - 1, currentDisk.pos.col] != null && // a disk exists board[currentDisk.pos.row - 1, currentDisk.pos.col].color == color && // matches your color !listContains(moves, new Pair(currentDisk.pos.row - 1, currentDisk.pos.col))) // hasn't yet been checked { diskQ.Enqueue(new Disk(currentDisk.pos.row - 1, currentDisk.pos.col, currentDisk.color)); moves.Add(new Pair(currentDisk.pos.row - 1, currentDisk.pos.col)); } } if (currentDisk.pos.row < (size - 1)) { // check south if (board[currentDisk.pos.row + 1, currentDisk.pos.col] != null && // a disk exists board[currentDisk.pos.row + 1, currentDisk.pos.col].color == color && // matches your color !listContains(moves, new Pair(currentDisk.pos.row + 1, currentDisk.pos.col))) // hasn't yet been checked { diskQ.Enqueue(new Disk(currentDisk.pos.row + 1, currentDisk.pos.col, currentDisk.color)); moves.Add(new Pair(currentDisk.pos.row + 1, currentDisk.pos.col)); } } if (currentDisk.pos.col > 0) { // check west if (board[currentDisk.pos.row, currentDisk.pos.col - 1] != null && // a disk exists board[currentDisk.pos.row, currentDisk.pos.col - 1].color == color && // matches your color !listContains(moves, new Pair(currentDisk.pos.row, currentDisk.pos.col - 1))) // hasn't yet been checked { diskQ.Enqueue(new Disk(currentDisk.pos.row, currentDisk.pos.col - 1, currentDisk.color)); moves.Add(new Pair(currentDisk.pos.row, currentDisk.pos.col - 1)); } } if (currentDisk.pos.col < (size - 1)) { // check east if (board[currentDisk.pos.row, currentDisk.pos.col + 1] != null && // a disk exists board[currentDisk.pos.row, currentDisk.pos.col + 1].color == color && // matches your color !listContains(moves, new Pair(currentDisk.pos.row, currentDisk.pos.col + 1))) // hasn't yet been checked { diskQ.Enqueue(new Disk(currentDisk.pos.row, currentDisk.pos.col + 1, currentDisk.color)); moves.Add(new Pair(currentDisk.pos.row, currentDisk.pos.col + 1)); } } // Check if we have won if (color == Player.Color.White && currentDisk.isLocated(size - 1, size - 1)) { return(true); } else if (color == Player.Color.Black && currentDisk.isLocated(size - 1, 0)) { return(true); } } // No more moves available return(false); }
private void placeDisk(int row, int col, Player.Color color) { board[row, col] = new Disk(row, col, color); }