Example #1
0
        /// Print available move coordinates and resulting points gained.
        public void PrintMoves(IReadOnlyCollection <Move> moves)
        {
            ColorPrint.Write($"  Possible moves ({moves.Count}):\n", Color.Yellow);
            // convert board from Disk enums to strings
            var boardStr = new List <string>(_board.Count);

            boardStr.AddRange(_board.Select(disk => disk.BoardChar()));
            foreach (var move in moves)
            {
                Console.WriteLine($"  {move}");
                var(x, y) = move.Square;
                boardStr[y * _size + x] = ColorPrint.Get(move.Value, Color.Yellow);
            }
            // print board with move positions
            Console.Write("   ");
            foreach (var i in _indices)
            {
                Console.Write($" {i}");
            }
            foreach (var y in _indices)
            {
                Console.Write($"\n  {y}");
                foreach (var x in _indices)
                {
                    Console.Write($" {boardStr[y * _size + x]}");
                }
            }
            Console.WriteLine("");
        }
Example #2
0
        public static void Main(string[] args)
        {
            ColorPrint.Write("OTHELLO GAME - C#\n", Color.Green);
            // try to read board size from command line args
            if (args.Length == 0 || !int.TryParse(args[0], out var boardSize))
            {
                boardSize = GetBoardSize();
            }
            else
            {
                Console.WriteLine($"Using board size: {boardSize}");
            }

            var game = new Othello(boardSize);

            game.Play();
        }
Example #3
0
        /// Print ending status and winner info.
        private void PrintResult()
        {
            Console.WriteLine("\n================================");
            ColorPrint.Write("The game is finished!\n", Color.Green);
            Console.WriteLine("Result:".Pastel(Color.Silver));
            PrintStatus();
            Console.WriteLine("");

            var winner = _board.Result();

            if (winner == Disk.Empty)
            {
                Console.WriteLine("The game ended in a tie...");
            }
            else
            {
                Console.WriteLine($"The winner is {winner.Name()}!");
            }
        }
Example #4
0
        /// Play one round as this player.
        public void PlayOneMove(Board board)
        {
            Console.WriteLine($"Turn: {_disk.Name()}");
            var moves = board.PossibleMoves(_disk);

            if (moves.Any())
            {
                _canPlay = true;
                if (_human && _showHelpers)
                {
                    board.PrintMoves(moves);
                }
                var chosenMove = _human ? GetHumanMove(moves) : GetComputerMove(moves);
                board.PlaceDisc(chosenMove);
                board.PrintScore();
                ++_roundsPlayed;
            }
            else
            {
                _canPlay = false;
                ColorPrint.Write("  No moves available...", Color.Yellow);
            }
        }