/// <summary>
 /// Print Board in Console
 /// </summary>
 /// <param name="board"></param>
 /// <param name="writer"></param>
 private void drawBoard(Board board, TextWriter writer)
 {
     var buf1 = new StringBuilder();
     var buf2 = new StringBuilder();
     writer.WriteLine("+--------------------------------+       +--------------------------------+");
     for (int k = 1; k <= 32; k++)
     {
         for (int i = 8; i > 0; i--)
         {
             int j = 1;
             if (i%2 == 0)
             {
                 j = 2;
                 buf1.AppendFormat("    ");
             }
             int shift;
             for (shift = 3; (j <= 8 && shift >= 0); j += 2, shift--)
             {
                 int cellNum = i*4 - shift;
                 var coord = board[i, j];
                 string soldierColor;
                 if (board.IsBlack(coord))
                 {
                     soldierColor = "b";
                     if (board.IsKing(coord)) soldierColor = "bk";
                 }
                 else if (board.IsWhite(coord))
                 {
                     soldierColor = "w";
                     if (board.IsKing(coord)) soldierColor = "wk";
                 }
                 else
                 {
                     soldierColor = ".";
                 }
                 k++;
                 buf1.AppendFormat(" | {0} |  ", soldierColor);
                 if (cellNum >= 1 && cellNum <= 9)
                 {
                     buf2.AppendFormat("  | {0} | ", cellNum);
                 }
                 else
                 {
                     buf2.AppendFormat("  | {0}| ", cellNum);
                 }
             }
             writer.WriteLine("{0}        {1}", buf1, buf2);
             writer.WriteLine("+--------------------------------+       +--------------------------------+");
             buf1.Length = 0;
             buf2.Length = 0;
         }
     }
     buf1.Append("|");
     buf2.Append("|");
 }
示例#2
0
 /// <summary>
 ///     Get Moves In Direction
 /// </summary>
 /// <param name="board"></param>
 /// <param name="coordinate"></param>
 /// <param name="player"></param>
 /// <returns></returns>
 public IList<Coordinate> GetMovesInDirection(Board board, Coordinate coordinate, Player player)
 {
     //Finds all optional move for player
     IList<Coordinate> coordinateList = OptionalMoves(board, coordinate, player);
     if (coordinateList.Count != 0)
     {
         //checks if player is the owner of the piece
         if (board.IsOwner(player, coordinate))
         {
             foreach (Coordinate item in coordinateList.Reverse())
             {
                 //Removing coordinates which are not in the piece direction white - forward and black backword (according to board orientation)
                 if (board.IsBlack(coordinate) && (board.IsSoldier(coordinate)))
                 {
                     if (item.X > coordinate.X)
                     {
                         coordinateList.Remove(item);
                     }
                 }
                 if (board.IsWhite(coordinate) && (board.IsSoldier(coordinate)))
                 {
                     if (item.X < coordinate.X)
                     {
                         coordinateList.Remove(item);
                     }
                 }
             }
         }
     }
     return coordinateList;
 }