private static void BlackMove(ref ChessBoard gameboard, ref string notation, List <string> gamestory, ref string move, ref int NumberOfMoves) { Console.SetCursorPosition(0, 12); Console.Write("Black, your move. Enter \"help\" if you don't know what to do"); Console.WriteLine(); notation = Console.ReadLine(); if (notation == "help") { Draw.PrintHelp(); Console.ReadLine(); return; } DefaultInfo.BlackEnPassantEndangered = false; try { gameboard = FIDEnotation.PerformBlackMove(gameboard, notation); NumberOfMoves++; move = move + " " + notation; if (!WhiteKing.IsSafe(gameboard)) { move += "+"; } gamestory.Add(move); move = ""; DefaultInfo.IsWhiteMove = !DefaultInfo.IsWhiteMove; } catch (ArgumentException) { // Console.WriteLine(e.Message); // BlackMove(ref gameboard, ref notation, gamestory, ref move, ref NumberOfMoves); return; } }
public void TestWhiteKingIsSafe() { ChessBoard board = new ChessBoard(); board['e', 8] = (sbyte)DefaultPieces.WhiteKing; board['e', 1] = (sbyte)DefaultPieces.BlackKing; Assert.IsTrue(WhiteKing.IsSafe(board)); board['e', 2] = (sbyte)DefaultPieces.BlackQueen; Assert.IsTrue(!WhiteKing.IsSafe(board)); board['e', 7] = 1; Assert.IsTrue(WhiteKing.IsSafe(board)); board['c', 6] = (sbyte)DefaultPieces.BlackQueen; Assert.IsTrue(!WhiteKing.IsSafe(board)); board['d', 7] = -1; board.DebugConsoleSimpleDraw(); Assert.IsTrue(WhiteKing.IsSafe(board)); board['a', 8] = (sbyte)DefaultPieces.BlackRook; Assert.IsTrue(!WhiteKing.IsSafe(board)); board['b', 8] = (sbyte)DefaultPieces.BlackkNight; Assert.IsTrue(WhiteKing.IsSafe(board)); board['c', 8] = (sbyte)DefaultPieces.BlackQueen; Assert.IsFalse(WhiteKing.IsSafe(board)); board['d', 8] = (sbyte)DefaultPieces.WhiteQueen; Assert.IsTrue(WhiteKing.IsSafe(board)); }
//TO DO drawns static void Main(string[] args) { ChessBoard gameboard = new ChessBoard(); gameboard.SetDefaultChessBoard(); DefaultInfo.SetDefaultValues(); string notation = ""; List <string> gamestory = new List <string>(); string move = ""; // Code Review: Назва локальної змінної повинна починатися з малої літери. int NumberOfMoves = 1; int rows = 20; int rowwidth = 20; //Draw.DrawChessBoard(gameboard); Console.Title = "Dan's True Chess Game"; do { DrawGameField(gameboard, gamestory, ref move, NumberOfMoves, ref rows, rowwidth); if (DefaultInfo.IsWhiteMove) { if (!FIDEnotation.CheckIfArePossibleMoves(gameboard, true)) { if (!WhiteKing.IsSafe(gameboard)) { DefaultInfo.BlackWin = true; } break; } WhiteMove(ref gameboard, ref notation, ref move); } else { if (!FIDEnotation.CheckIfArePossibleMoves(gameboard, false)) { if (!BlackKing.IsSafe(gameboard)) { DefaultInfo.WhiteWin = true; } break; } BlackMove(ref gameboard, ref notation, gamestory, ref move, ref NumberOfMoves); } }while (true); if (DefaultInfo.WhiteWin) { gamestory[gamestory.Count] += "+"; move = " "; DrawGameField(gameboard, gamestory, ref move, NumberOfMoves, ref rows, rowwidth); Console.WriteLine("White win!"); } if (DefaultInfo.BlackWin) { gamestory[gamestory.Count - 1] += "+"; move = " "; DrawGameField(gameboard, gamestory, ref move, NumberOfMoves, ref rows, rowwidth); Console.WriteLine("Black win!"); } else { gamestory[gamestory.Count] += "="; move = " "; DrawGameField(gameboard, gamestory, ref move, NumberOfMoves, ref rows, rowwidth); Console.WriteLine("Draw"); } }