Ejemplo n.º 1
0
        // -----------------------------------------------------------------------------------

        private Cell choosePiece(Chessboard board)
        {
            Cell position = new Cell();

            for (bool ok = false; !ok;)
            {
                position = InputManager.getPosition();
                var piece = board.GetPiece(position);
                if (piece == null)
                {
                    System.Console.WriteLine("\nIn questa casella non è persente un pezzo, indicarne un'altra");
                }
                else if (piece.team != team)
                {
                    System.Console.WriteLine("\nNon puoi muovere i pezzi dell'altra squadra!");
                }
                else if (piece.Moves(board, position).Count == 0)
                {
                    System.Console.WriteLine("\nIl pezzo {0} non può muoversi", piece.ToString());
                }
                else
                {
                    ok = true;
                }
            }
            return(position);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Chesspiece selectedPiece = null;
            Chessboard chessboard    = new Chessboard();

            while (!chessboard.isGameOver)
            {
                Console.WriteLine("1 = GetPiece(row, column)");
                Console.WriteLine("2 = Move(initRow, initCol, toRow, toCol)");
                Console.WriteLine("3 = PrintBoard()");
                Console.WriteLine("───────────────────────────┼");
                Console.Write("Choice: ");
                if (int.TryParse(Console.ReadLine(), out int choice))
                {
                    int selectedRow;
                    int selectedCol;
                    switch (choice)
                    {
                    case 1:
                        Console.Write("Enter Row: ");
                        selectedRow = int.Parse(Console.ReadLine());
                        Console.Write("Enter Column: ");
                        selectedCol = int.Parse(Console.ReadLine());

                        selectedPiece = chessboard.GetPiece(selectedRow, selectedCol);
                        break;

                    case 2:
                        Console.Write("Enter initial Row: ");
                        selectedRow = int.Parse(Console.ReadLine());
                        Console.Write("Enter initial Column: ");
                        selectedCol = int.Parse(Console.ReadLine());

                        Console.Write("Enter final Row: ");
                        int finalRow = int.Parse(Console.ReadLine());
                        Console.Write("Enter final Column:");
                        int finalCol = int.Parse(Console.ReadLine());

                        chessboard.move(selectedRow, selectedCol, finalRow, finalCol);
                        break;

                    case 3:
                        chessboard.PrintBoard();
                        break;
                    }
                }
            }


            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public override Move NextMove(Chessboard board)
        {
            var oldPosition = choosePiece(board);
            var piece       = board.GetPiece(oldPosition);
            var moves       = piece.Moves(board, oldPosition);

            var targets = new List <Cell>();

            foreach (var m in moves)
            {
                targets.Add(m.to);
            }

            renderer.DrawChessboard(board, team, oldPosition, targets);

            var newPosition = chooseTargetCell(board, targets);

            return(new Move {
                piece = piece, from = oldPosition, to = newPosition
            });
        }