/// <summary> /// Counts the number of discs of a given color on the board. /// (works for Disc.Empty) /// </summary> /// <param name="board">The game board</param> /// <param name="color">The player color</param> /// <returns>The disc count</returns> public static int CountDiscs(Disc[,] board, Disc color) { int count = 0; foreach (Point p in board.PointsIterator()) if (board.At(p) == color) count++; return count; }
/// <summary> /// Counts the number of discs of a given color on the board. /// (works for Disc.Empty) /// </summary> /// <param name="board">The game board</param> /// <param name="color">The player color</param> /// <returns>The disc count</returns> public static int CountDiscs(Disc[,] board, Disc color) { return board.PointsIterator().Count(p => board.At(p) == color); }
/// <summary> /// Returns the set of valid moves for a given board and a given player /// </summary> /// <param name="board">The game board</param> /// <param name="currentPlayer">The current player</param> /// <returns>A set of valid play points</returns> public static ISet<Point> ValidMoves(Disc[,] board, Disc currentPlayer) { HashSet<Point> validMoves = new HashSet<Point>(); foreach (Point p in board.PointsIterator()) if (IsValidMove(board, p, currentPlayer)) validMoves.Add(p); return validMoves; }