private static void WhiteMove(ref ChessBoard gameboard, ref string notation, ref string move) { Console.SetCursorPosition(0, 12); Console.Write("White, 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.WhiteEnPassantEndangered = false; try { gameboard = FIDEnotation.PerformWhiteMove(gameboard, notation); move = move + " " + notation; if (!BlackKing.IsSafe(gameboard)) { move += "+"; } DefaultInfo.IsWhiteMove = !DefaultInfo.IsWhiteMove; } catch (ArgumentException) { //Console.WriteLine(e.Message); return; // WhiteMove(ref gameboard, ref notation, ref move); } }
public void TestBlackKingIsSafe() { ChessBoard board = new ChessBoard(); board['e', 1] = (sbyte)DefaultPieces.BlackKing; board['e', 8] = (sbyte)DefaultPieces.WhiteKing; Assert.IsTrue(BlackKing.IsSafe(board)); board['e', 7] = (sbyte)DefaultPieces.WhiteQueen; Assert.IsTrue(!BlackKing.IsSafe(board)); board['e', 2] = -1; Assert.IsTrue(BlackKing.IsSafe(board)); board['c', 3] = (sbyte)DefaultPieces.WhiteQueen; Assert.IsTrue(!BlackKing.IsSafe(board)); board['d', 2] = 1; Assert.IsTrue(BlackKing.IsSafe(board)); board['a', 1] = (sbyte)DefaultPieces.WhiteRook; Assert.IsTrue(!BlackKing.IsSafe(board)); board['b', 1] = (sbyte)DefaultPieces.WhitekNight; Assert.IsTrue(BlackKing.IsSafe(board)); board['c', 1] = (sbyte)DefaultPieces.WhiteQueen; Assert.IsFalse(BlackKing.IsSafe(board)); board['d', 1] = (sbyte)DefaultPieces.BlackQueen; Assert.IsTrue(BlackKing.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"); } }