private void TryMovePlayerPiece(PlayerType ptype, Pos from, Pos to) { var idx = GetPlayerIndex(ptype); // var gs = GetPiece(_pmap, from); var gs = GetPiece(idx, from); if (gs == null) { var cx = CoordinateTrans.XtoA(from.x); var cy = CoordinateTrans.YtoA(from.y); throw new PieceDoesNotExistException( $"Threre is NOT a PIECE in ({cx},{cy}) or ({from.x},{from.y})."); } // var friend = GetPiece(_pmap, to); var friend = GetPiece(idx, to); if (friend != null) { var cx = CoordinateTrans.XtoA(from.x); var cy = CoordinateTrans.YtoA(from.y); throw new PieceDoesNotExistException( $"Threre is a FRIEND PIECE in ({cx},{cy}) or ({from.x},{from.y})."); } // requires System.Linq.Enumerable; // var e_indices = // from i in Enumerable.Range(0, players.Length) where i != idx select i; // foreach (int i in e_indices) { for (int i = 0; i < players.Length; i++) { if (i == idx) { continue; } var enemy = GetPiece(i, to); if (enemy != null) { MarkAsTaken(i, to); break; } } Move(idx, from, to); // var enemy = GetPiece(1, to); // if (enemy != null) { // MarkAsTaken(1, to); // } // Move(0, from ,to); return; }
public void DispPieceInfo() { Console.WriteLine(" 1 2 3 4 5 6"); Console.WriteLine(" +---+---+---+---+---+---+"); for (int x = 0; x < 6; x++) { String str = " " + CoordinateTrans.XtoA(x) + " |"; for (int y = 0; y < 6; y++) { if (players[0].map[x, y] != null) { var sym = GetPieceTypeSymbol(players[0].map[x, y]); if ((x == 0 || x == 5) && (y == 0 || y == 5)) { str += "(" + sym + ")|"; } else { str += " " + sym + " |"; } } else if (players[1].map[x, y] != null) { var sym = GetPieceTypeSymbol(players[1].map[x, y]); if ((x == 0 || x == 5) && (y == 0 || y == 5)) { str += "(" + sym + ")|"; } else { str += " " + sym + " |"; } } else { if ((x == 0 || x == 5) && (y == 0 || y == 5)) { str += "( )|"; } else { str += " |"; } } } Console.WriteLine(str); Console.WriteLine(" +---+---+---+---+---+---+"); } }
public void TryMovePiece(PlayerType ptype, Pos from, Direction dir) { var to = from + CalcDiff(ptype, dir); Console.WriteLine($"------> {from.x} {from.y}"); Console.WriteLine($"------> {CalcDiff(ptype, dir).x} {CalcDiff(ptype, dir).y}"); if (WithIn(to) == false) { var cx = CoordinateTrans.XtoA(to.x); var cy = CoordinateTrans.YtoA(to.y); throw new OutOfBoardAreaPositionException( $"({cx},{cy}) or ({to.x},{to.y}) is out of board area ({BoardHeight},{BoardWidth})."); } TryMovePlayerPiece(ptype, from, to); }
public void DispCurrentMap() { Console.WriteLine(" 1 2 3 4 5 6"); Console.WriteLine(" +---+---+---+---+---+---+"); for (int x = 0; x < 6; x++) { String str = " " + CoordinateTrans.XtoA(x) + " |"; for (int y = 0; y < 6; y++) { if (players[0].map[x, y] != null) { // if(_pmap[x, y] != null) { if ((x == 0 || x == 5) && (y == 0 || y == 5)) { str += "(^)|"; } else { str += " ^ |"; } // } else if(_emap[x, y] != null) { } else if (players[1].map[x, y] != null) { if ((x == 0 || x == 5) && (y == 0 || y == 5)) { str += "(v)|"; } else { str += " v |"; } } else { if ((x == 0 || x == 5) && (y == 0 || y == 5)) { str += "( )|"; } else { str += " |"; } } } Console.WriteLine(str); Console.WriteLine(" +---+---+---+---+---+---+"); } Console.WriteLine(""); Console.WriteLine("Taken Pieces"); Console.WriteLine(" Player1"); Console.Write(" Good :"); foreach (Piece gs in players[0].taken_goods) { Console.Write(" v"); } Console.Write(Environment.NewLine); Console.Write(" Bad :"); foreach (Piece gs in players[0].taken_bads) { Console.Write(" v"); } Console.Write(Environment.NewLine); Console.WriteLine(" Player2 :"); Console.Write(" Good :"); foreach (Piece gs in players[1].taken_goods) { Console.Write(" ^"); } Console.Write(Environment.NewLine); Console.Write(" Bad :"); foreach (Piece gs in players[1].taken_bads) { Console.Write(" ^"); } Console.Write(Environment.NewLine); }