public void Test_002() { // Model // View // Controller var moves = new List <string>() { // White, Black "G1F3", "G8F6", "C2C4", "G7G6", "B1C3", "F8G7", "D1D4", "E8G8", // castle "C1C4", "D7D5", "D1B3", "D5C4", // capture "B3C4", // capture, ... }; var game = new Chess(); var board = new Board(); var printer = new BoardPrinter(); //board.Move += (move) => Debug.WriteLine(""); //game.Result += (result) => Debug.WriteLine(""); //game.Capture += (piece, position) => Debug.WriteLine(""); foreach (var move in moves) { game.Apply(move, board); printer.Show(board); } }
public ConsoleUI(GameFlow gameFlow, IConsoleIO console, IStorage storage, RulesEngine rulesEngine) { if (gameFlow is null) { throw new ArgumentNullException(nameof(gameFlow)); } if (console is null) { throw new ArgumentNullException(nameof(console)); } if (storage is null) { throw new ArgumentNullException(nameof(storage)); } if (rulesEngine is null) { throw new ArgumentNullException(nameof(rulesEngine)); } GameCmdHandler = new GameCmdHandler(gameFlow, storage, console); TurnCmdHandler = new TurnCmdHandler(rulesEngine); BoardPrinter = new BoardPrinter(console, gameFlow); CommandParser = new CommandParser(); CommandCycle = new CommandCycle(console, GameCmdHandler, TurnCmdHandler, BoardPrinter, CommandParser); }
public void Into_ShouldWriteInto() { string rn = Environment.NewLine; //Arrange CellCollection cellCollection = new CellCollection(new ICell[] { new UnselectedCell(new Glyph('0')), new UnselectedCell(new Glyph('1')), new UnselectedCell(new Glyph('2')), new UnselectedCell(new Glyph('3')), new UnselectedCell(new Glyph('4')), new UnselectedCell(new Glyph('5')), new UnselectedCell(new Glyph('6')), new UnselectedCell(new Glyph('7')), new UnselectedCell(new Glyph('8')) }); FakeWriter fakeWriter = new FakeWriter(); BoardPrinter subject = new BoardPrinter(cellCollection, fakeWriter); //Act subject.Print(); //Assert fakeWriter.AssertLinesWritten($" 0 | 1 | 2{rn}===+===+==={rn} 3 | 4 | 5{rn}===+===+==={rn} 6 | 7 | 8{rn}"); }
static void PrintBoardAfterMove(IPlayerMove move, string playerName, BoardPrinter board) { var piece = board.Get(move.Move.StartPosition.ToTuple()); if (move.Move.PromotionResult != PromotionPieceType.NoPromotion) { if (piece.Contains("w")) { piece = "wQ "; } else { piece = "bQ "; } } // Clear previous move for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (board.Get((i, j)) == BoardPrinter.PreviousTileValue) { board.Set((i, j), " "); break; } } } board.Set(move.Move.StartPosition.ToTuple(), BoardPrinter.PreviousTileValue); board.Set(move.Move.EndPosition.ToTuple(), piece); board.Print(); }
public void Test_002() { //Model //View //Controller var moves = new List <string>() { //white, Black - COLLECTION OF STRINGS TO REPRESENT MOVES "G1F3", "G8F6", "C2C4", "G7G6", "B1C3", "F8G7", "D1D4", "E8G8", //CASTLE "C1C4", "D7D5", "D1B3", "D5C4", //CAPTURE "B3C4", //CAPTURE }; var game = new Chess(); // refer to class library- view var board = new Board(); // refer to class library -model var printer = new BoardPrinter(); //printing to the console //board.Move += (moves) => Debug.WriteLine("");//we want an event and I have to declare that myself. //game.Result += (result) => Debug.WriteLine(""); //game.Capture += (piece, position) => Debug.WriteLine(""); foreach (var move in moves) { game.Apply(move, board); //representing the chess board; apply method to the board as a parameter; the method can be somewhere else. printer.Show(board); } }
static void Main(string[] args) { BoardPrinter printer = new BoardPrinter(); var othello = new Othello(); othello.Start(Color.White); othello.Set(3, 3); othello.Set(3, 4); othello.Set(4, 4); othello.Set(4, 3); printer.Print("オリジナル", othello); var snapshot = othello.Save(); // 適当に石を追加しておく othello.Set(1, 1); othello.Set(5, 5); othello.Set(7, 7); printer.Print("オリジナル(追加後)", othello); // 復元 var replay = new Othello(); replay.Load(snapshot); printer.Print("復元", replay); }
static void Main(string[] args) { FileReader filereader = new FileReader(); Board board = new Board(); BoardPrinter boardprinter = new BoardPrinter(); bool[,] x = filereader.MakeBoard(@"C:\Users\FIT\Ejercicio-Kiosko\Ejercicio4\src\Library\Prueba.txt"); bool[,] y = board.GameLogic(x); boardprinter.PrintBoard(y); }
public void MovePointerUp() { BoardPrinter.BackspaceCursorFromPosition(cursorCurrentPositionX, cursorCurrentPositionY); cursorCurrentPositionY--; if (cursorCurrentPositionY == -1) { cursorCurrentPositionY = BoardSize - 1; } BoardPrinter.PrintCursorToPosition(cursorCurrentPositionX, cursorCurrentPositionY); }
public void MovePointerDown() { BoardPrinter.BackspaceCursorFromPosition(cursorCurrentPositionX, cursorCurrentPositionY); cursorCurrentPositionY++; if (cursorCurrentPositionY == BoardSize) { cursorCurrentPositionY = 0; } BoardPrinter.PrintCursorToPosition(cursorCurrentPositionX, cursorCurrentPositionY); }
static void Main(string[] args) { var placements = GameHard(); var board = new GameBoard(placements); var printer = new BoardPrinter(); printer.Print(board); var solver = new Solver(); board = solver.Solve(board); printer.Print(board); }
public ConsoleUI(GameFlow gameFlow, IConsoleIO console, IStorage storage, RulesEngine rulesEngine) { CheckArg.NotNull(gameFlow); CheckArg.NotNull(console); CheckArg.NotNull(storage); CheckArg.NotNull(rulesEngine); GameCmdHandler = new GameCmdHandler(gameFlow, storage, console); TurnCmdHandler = new TurnCmdHandler(rulesEngine); BoardPrinter = new BoardPrinter(console, gameFlow); CommandParser = new CommandParser(); CommandCycle = new CommandCycle(console, GameCmdHandler, TurnCmdHandler, BoardPrinter, CommandParser); }
public CommandCycle( IConsoleIO consoleIO, GameCmdHandler gameCmdHandler, TurnCmdHandler turnCmdHandler, BoardPrinter boardPrinter, CommandParser commandParser) { Console = consoleIO; GameCmdHandler = gameCmdHandler; TurnCmdHandler = turnCmdHandler; BoardPrinter = boardPrinter; CommandParser = commandParser; }
public void PrintBoard_InitiateBoardWith5RowsAnd5Columns_ResultStringContains143CharactersIncludingBoardDelimiters() { Board board = new(rowCount : 5, columnCount : 5); board.PlaceCharTile(X: 1, Y: 2, c: new CharTile('H')); board.PlaceCharTile(X: 2, Y: 2, c: new CharTile('E')); board.PlaceCharTile(X: 3, Y: 2, c: new CharTile('L')); board.PlaceCharTile(X: 4, Y: 2, c: new CharTile('L')); board.PlaceCharTile(X: 5, Y: 2, c: new CharTile('O')); string boardString = BoardPrinter.PrintBoard(board); Assert.IsTrue(boardString.Length == 143); }
public void Setup() { _boardInitializerDouble = A.Fake <BoardInitializer>(); _consoleWrapperDouble = A.Fake <ConsoleWrapper>(); _boardPrinterDouble = A.Fake <BoardPrinter>(); _consoleCoordinateReaderDouble = A.Fake <ConsoleCoordinatesReader>(); _inputMapperDouble = A.Fake <CoordinatesMapper>(); _shotResultMapperDouble = A.Fake <ShotResultMapper>(); _subject = new ConsoleGame( _boardInitializerDouble, _consoleWrapperDouble, _boardPrinterDouble, _consoleCoordinateReaderDouble, _inputMapperDouble, _shotResultMapperDouble); }
public void Test_003() { var moves = new List <string>() { // White, Black "G1F3", "G8F6", "C2C4", "G7G6", "B1C3", "F8G7", "D1D4", "E8G8", // castle "C1C4", "D7D5", "D1B3", "D5C4", // capture "B3C4", // capture, ... }; var printer = new BoardPrinter(); ChessMove result = null; var gameMoves = new List <ChessMove>(); foreach (var move in moves) { if (ChessMove.Try(move, ref result)) { Debug.WriteLine($""); Debug.WriteLine($"Move Number: {result.MoveNumber}"); Debug.WriteLine($"Origin: {result.Move.Substring(0, 2)}"); Debug.WriteLine($"Destination: {result.Move.Substring(2, 2)}"); Debug.WriteLine($""); printer.Show(result.Before); printer.Show(result.After); gameMoves.Add(result); } else { break; } } }
int IConsoleApplication.Run(string[] args) { PrintWelcome(); while (true) { BoardPrinter.PrintCurrentGameState(); Console.Write("> "); string cmdStr = Console.ReadLine(); try { var cmd = CommandParser.Parse(cmdStr); if (cmd is TurnCommand tc) { MakeTurn(tc.Turn); } else if (cmd is GameCommand gc) { GameCmdHandler.Execute(gc); } else if (cmd is Exit) { return(0); } else { throw new NotImplementedException($"Not implemented command: {cmd}"); } } catch (UserErrorException ue) { PrintError(ue); PrintHelp(); } } }
/// <summary> /// Starts the game /// </summary> /// <param name="allowedShips"></param> /// <param name="boardSize"></param> public void Start(IReadOnlyList <Type> allowedShips = null, int boardSize = 10) { AllowedShips = allowedShips ?? new List <Type> { typeof(AircraftCarrier), typeof(Ships.Battleship), typeof(Submarine), typeof(Cruiser), typeof(Destroyer) }; BoardSize = boardSize; // add player var players = GetPlayers(); _players.AddRange(players); _players.ForEach(p => PlaceShips(p)); Status = GameStatus.Started; BoardPrinter.PrintBoard(this); }
static void Main(string[] args) { RandomGoalBoardGenerator bg = new RandomGoalBoardGenerator(30, 20, 5, 123); BoardPrinter.Print(bg.CreateBoard()); }
public override void PrintView() { BoardPrinter.CursorStartPosition_X = CurragePositionX; BoardPrinter.CursorStartPosition_Y = CurragePositionY; BoardPrinter.PrintView(); }
public void PrintBoard() { BoardPrinter.Print(Fields); }
public void HandleMessage(Data message) { if (message.PlayerLocation != null) { Player.game.Location = message.PlayerLocation; ConsoleDebug.Message($"My location: ({message.PlayerLocation.x}, {message.PlayerLocation.y})"); } if (message.TaskFields != null) { Common.SchemaWrapper.TaskField[] taskFields = new Common.SchemaWrapper.TaskField[message.TaskFields.Length]; for (int i = 0; i < taskFields.Length; i++) taskFields[i] = new Common.SchemaWrapper.TaskField(message.TaskFields[i]); Player.game.UpdateFields(taskFields); ; } if (message.GoalFields != null) { Common.SchemaWrapper.GoalField[] goalFields = new Common.SchemaWrapper.GoalField[message.GoalFields.Length]; for (int i = 0; i < goalFields.Length; i++) goalFields[i] = new Common.SchemaWrapper.GoalField(message.GoalFields[i]); Player.game.UpdateFields(goalFields); } if (message.Pieces != null) { foreach (Piece piece in message.Pieces) { lock (pieceLock) { if (piece.playerIdSpecified) { Player.game.Pieces = Player.game.Pieces.Where(piece1 => piece1.playerId != piece.playerId).ToList(); } if (Player.game.Pieces.Count(p => p.id == piece.id) == 0) Player.game.Pieces.Add(piece); else { var pp = Player.game.Pieces.Single(p => p.id == piece.id); pp.playerId = piece.playerId; pp.playerIdSpecified = piece.playerIdSpecified; pp.timestamp = piece.timestamp; if (pp.type == PieceType.unknown) pp.type = piece.type; } } } //args.PlayerClient.Pieces.Clear(); //foreach (var piece in message.Pieces) //{ // args.PlayerClient.Pieces.Add(piece); //} } if (message.gameFinished == true) { ConsoleDebug.Good("\nGame just ended\n"); BoardPrinter.Print(Player.game.Fields); Player.RegisterForNextGameAfterGameEnd(); return; } Player.ReadyForAction?.Invoke(); }
/// <summary> /// Obtain a string representation of the game board /// </summary> public string GetBoard(IEnumerable <Field> pullFields, IEnumerable <Field> pushFields) { return(BoardPrinter.GetBoard(Size, Nodes, Arcs, pullFields, pushFields)); }
public static void Start(int minDelayInMs, int?overrideOpponentMaxDepth, Board?overrideBoard = null) { Log(Environment.NewLine); // TODO async var moveHistory = new List <IPlayerMove>(); var info1 = new StartInformationImplementation() { WhitePlayer = true }; var player1 = new Logic(info1, null, overrideBoard); var board = new BoardPrinter(player1.Board.InterfacePieces, OperatingSystem.IsWindows()); var firstMove = player1.CreateMove(); moveHistory.Add(firstMove); PrintMove(firstMove, "white"); PrintBoardAfterMove(firstMove, "", board); var info2 = new StartInformationImplementation() { WhitePlayer = false, OpponentMove = firstMove.Move }; var player2 = new Logic(info2, overrideOpponentMaxDepth, overrideBoard); try { while (true) { var move = player2.CreateMove(); moveHistory.Add(move); PrintMove(move, "black"); PrintBoardAfterMove(move, "", board); if (move.Move.CheckMate) { Log("Checkmate"); break; } if (MoveHistory.IsDraw(moveHistory)) { Log("Draw"); break; } player1.ReceiveMove(move.Move); Thread.Sleep(minDelayInMs); move = player1.CreateMove(); moveHistory.Add(move); PrintMove(move, "white"); PrintBoardAfterMove(move, "", board); if (move.Move.CheckMate) { Log("Checkmate"); break; } if (MoveHistory.IsDraw(moveHistory)) { Log("Draw"); break; } player2.ReceiveMove(move.Move); Thread.Sleep(minDelayInMs); } } catch (Exception e) { Console.WriteLine(e); } Console.Read(); }
public void SetUp() { _board = new Board(TestBoardSize); _mockPrintTarget = new MockPrintTarget(); _boardPrinter = new BoardPrinter(_mockPrintTarget); _expectedNumberOfOutputLines = _board.BoardSize * 2 + 1; }
public void PrintBoard() { BoardPrinter.PrintAlternative(Board); }
public void SetUp() { _positionStateMapperDouble = A.Fake <PositionStateMapper>(); _subject = new BoardPrinter(_positionStateMapperDouble); }
public override void RemoveViewFromScreen() { BoardPrinter.RemoveView(); }