Example #1
0
 public Square(SquareColour colour, Piece occupier, int row, int column)
 {
     Colour   = colour;
     Occupier = occupier;
     Row      = row;
     Column   = column;
 }
Example #2
0
 public void Initialise()
 {
     _grid.Clear();
     for (int row = 0; row < 8; row++)
     {
         for (int column = 0; column < 8; column++)
         {
             SquareColour colour = (row % 2 == 0 ? (column % 2 == 0 ? SquareColour.Yellow : SquareColour.White) : (column % 2 == 0 ? SquareColour.White : SquareColour.Yellow));
             Piece        piece  = ((row < 3 || row > 4) && colour == SquareColour.Yellow) ?
                                   (row < 3 ? new Piece(PieceColour.Black, this, row, column, _game.BlackPlayer) : new Piece(PieceColour.White, this, row, column, _game.WhitePlayer))
                 : null;
             _grid[row, column] = new Square(colour, piece, row, column);
         }
     }
 }
Example #3
0
        public void Display(BoardState state, Player player, Move bestMove = null, bool clearFirst = true, IEnumerable <Move> allMoves = null)
        {
            if (allMoves != null)
            {
                string log = "Valid moves are: ";
                foreach (Move move in allMoves)
                {
                    log += "(" + move.Start.Row + ", " + move.Start.Column + ") : (" + move.End.Row + ", " + move.End.Column + "); ";
                }
                Log(log);

                if (bestMove != null)
                {
                    Log("Best move is: (" + bestMove.Start.Row + ", " + bestMove.Start.Column + ") : (" + bestMove.End.Row + ", " + bestMove.End.Column + ")");
                }
            }

            if (clearFirst)
            {
                Console.Clear();
            }
            else
            {
                Console.SetCursorPosition(0, 0);
            }

            Console.WriteLine("SuperDraughts (C)2016 Zero Point Systems Ltd");
            Console.WriteLine("--------------------------------------------");
            Console.Write("\n");
            Console.Write(player.Name + " (" + player.Colour.ToString() + ") plays                     \n\n");

            SquareColour current = SquareColour.Yellow;

            Console.Write("\t 01234567");
            for (int i = 0; i < 8; i++)
            {
                Console.Write("\t\n\t" + i.ToString());
                for (int j = 0; j < 8; j++)
                {
                    if (current == SquareColour.White)
                    {
                        Console.BackgroundColor = ConsoleColor.White;
                    }
                    else
                    {
                        Console.BackgroundColor = ConsoleColor.DarkYellow;
                    }

                    if (bestMove != null && bestMove.Start.Row == i && bestMove.Start.Column == j)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                    }

                    if ((bestMove != null && (bestMove.Steps.Any(x => x.Row == i && x.Column == j)) || (allMoves != null && allMoves.Any(m => m.Steps.Any(x => x.Row == i && x.Column == j)))))
                    {
                        Console.BackgroundColor = player.Colour == PieceColour.Black ? ConsoleColor.Red : ConsoleColor.Blue;
                    }

                    PieceInfo piece = state.For(i, j).PieceInfo;
                    if (piece == null)
                    {
                        Console.Write(" ");
                    }
                    else
                    {
                        if (piece.IsCrowned)
                        {
                            Console.ForegroundColor = piece.Colour == PieceColour.Black ? ConsoleColor.Black : ConsoleColor.White;
                            Console.Write("0");
                        }
                        else
                        {
                            Console.ForegroundColor = piece.Colour == PieceColour.Black ? ConsoleColor.Black : ConsoleColor.White;
                            Console.Write("O");
                        }
                    }

                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.White;
                    current = current == SquareColour.Yellow ? SquareColour.White : SquareColour.Yellow;
                }
                current = current == SquareColour.Yellow ? SquareColour.White : SquareColour.Yellow;
            }
            Console.Write("\t\n\n");
            Console.Write("Black has " + state.BlackPiecesRemaining + " pieces remaining, White has " + state.WhitePiecesRemaining + " pieces remaining.    ");
        }