コード例 #1
0
 public void PlayGame(ArrayList moves, ArrayList englishEquivalent, int modifier)
 {
     for (int i = 0; i < moves.Count; i++)
     {
         if (chessBoard.Move(moves[i].ToString()))
         {
             Parser.PrintInfo(moves[i].ToString(), englishEquivalent[i + modifier].ToString());
         }
         Parser.PrintBoard();
     }
 }
コード例 #2
0
        public void PlacePieces(ArrayList placements, ArrayList englishEquivalent)
        {
            for (int i = 0; i < placements.Count; i++)
            {
                char file = placements[i].ToString().ElementAt(2);
                int  rank = int.Parse(placements[i].ToString().Substring(3, 1)) - 1;

                int fileAsInt;
                switch (file)
                {
                case 'a':
                    fileAsInt = 0;
                    break;

                case 'b':
                    fileAsInt = 1;
                    break;

                case 'c':
                    fileAsInt = 2;
                    break;

                case 'd':
                    fileAsInt = 3;
                    break;

                case 'e':
                    fileAsInt = 4;
                    break;

                case 'f':
                    fileAsInt = 5;
                    break;

                case 'g':
                    fileAsInt = 6;
                    break;

                case 'h':
                    fileAsInt = 7;
                    break;

                default:
                    fileAsInt = 0;
                    break;
                }
                //english here
                Parser.PrintInfo(placements[i].ToString(), englishEquivalent[i].ToString());
                chessBoard.SetPieces(rank, fileAsInt, placements[i].ToString().ElementAt(0), placements[i].ToString().ElementAt(1));
                Parser.PrintBoard();
            }
        }
コード例 #3
0
ファイル: Board.cs プロジェクト: vanBras/Pro100
        public bool Move(string movement)
        {
            //return to bool eventually

            /*
             * piece.move() pass x and y for new space
             */
            if (movement.Length == 5)
            {
                int currentFile = CharToInt(movement[0]);
                int currentRank = int.Parse(movement[1].ToString()) - 1;
                int newFile     = CharToInt(movement[3]);
                int newRank     = int.Parse(movement[4].ToString()) - 1;
                if (boardSpaces[currentRank, currentFile].HasPiece())
                {
                    Piece movingPiece = boardSpaces[currentRank, currentFile].GetPiece();
                    if (movingPiece.Move(movingPiece.GetPieceType(), currentRank, currentFile, newRank, newFile))
                    {
                        string pieceString = movingPiece.GetPieceString();
                        boardSpaces[newRank, newFile].AddPiece(pieceString[1], pieceString[0]);
                        boardSpaces[currentRank, currentFile].RemovePiece();
                        return(true);
                    }
                    else
                    {
                        Parser.PrintInfo(movement, "This is an invalid move.\n");
                        return(false);
                    }
                }
                else
                {
                    Parser.PrintInfo(movement, "The stating space does not contain a piece to move.\n");
                    return(false);
                }
            }
            else
            {
                string firstMove  = string.Concat(movement[0], movement[1], movement[3], movement[4]);
                string secondMove = string.Concat(movement[6], movement[7], movement[9], movement[10]);
                if (Move(firstMove) && Move(secondMove))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
コード例 #4
0
        public void PlayGame()
        {
            bool lightsTurn = true;

            while (true)
            {
                if (lightsTurn)
                {
                    Console.WriteLine("It is Light's Turn.");
                    string move = Console.ReadLine();
                    string message;
                    if (Parser.ParseLine(move, out message))
                    {
                        if (Board.GetBoardSpace(move[1] - '0' - 1, move[0] - 'a').GetPiece().GetColor().Equals("Light"))
                        {
                            if (chessBoard.Move(move))
                            {
                                if (!chessBoard.DetermainCheck("Light"))
                                {
                                    lightsTurn = false;
                                    Parser.PrintInfo(move, message);
                                    if (chessBoard.DetermainCheck("Dark"))
                                    {
                                        Console.WriteLine("The Dark king is in Check.");
                                    }
                                }
                                else
                                {
                                    string undoMove = move[3].ToString() + move[4].ToString() + move[2].ToString() + move[0].ToString() + move[1].ToString();
                                    chessBoard.Move(undoMove);
                                    message = "That places you in check.";
                                }
                            }
                            Parser.PrintBoard();
                        }
                        else
                        {
                            Console.WriteLine("That was not your piece.");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("It is Dark's Turn.");
                    string move = Console.ReadLine();
                    string message;
                    if (Parser.ParseLine(move, out message))
                    {
                        if (Board.GetBoardSpace(move[1] - '0' - 1, move[0] - 'a').GetPiece().GetColor().Equals("Dark"))
                        {
                            if (chessBoard.Move(move))
                            {
                                if (!chessBoard.DetermainCheck("Light"))
                                {
                                    lightsTurn = true;
                                    Parser.PrintInfo(move, message);
                                    if (chessBoard.DetermainCheck("Light"))
                                    {
                                        Console.WriteLine("The Light king is in Check.");
                                    }
                                }
                                else
                                {
                                    string undoMove = move[3].ToString() + move[4].ToString() + move[2].ToString() + move[0].ToString() + move[1].ToString();
                                    chessBoard.Move(undoMove);
                                    message = "That places you in check.";
                                }
                                Parser.PrintBoard();
                            }
                            else
                            {
                                Console.WriteLine("That was not your piece.");
                            }
                        }
                    }
                }
            }
        }