public MatchModelBase(string fen, List <BoardPosition> fromPositions, List <BoardPosition> toPositions, List <IPlayer> playerList, ChessGameType chessGameType_, IGameLoaderSaverService gameLoaderSaverService_) { if (fen == null) { throw new NullReferenceException("FEN String Was Not Set!"); } if (playerList == null) { throw new NullReferenceException("Player List Was Not Set!"); } bool isAnyPlayerNotImplemented = false; foreach (var player in playerList) { if (player == null) { isAnyPlayerNotImplemented = true; break; } } if (isAnyPlayerNotImplemented) { throw new NullReferenceException("One Or More Players In List Were Not Set!"); } if (fromPositions == null) { throw new NullReferenceException("From-Positions Is Null!"); } if (toPositions == null) { throw new NullReferenceException("To-Positions Is Null!"); } if (gameLoaderSaverService_ == null) { throw new NullReferenceException("GameLoaderSaverService Not Set!"); } Players = playerList; chessGameType = chessGameType_; gameLoaderSaverService = gameLoaderSaverService_; this.PreviousSelectedPosition = BoardPosition.None; this.CurrentSelectedPosition = BoardPosition.None; CurrentPlayer = playerList[0]; PreviousPlayer = playerList.Last(); foreach (var player in playerList) { player.InitInterfaces(this, this, this, this); } }
public void SetCircledMatchMenu() { playVersusComputer_toggle.gameObject.SetActive(false); choosePlayr_text.gameObject.SetActive(false); whitePlayer_toggle.gameObject.SetActive(false); blackPlayer_toggle.gameObject.SetActive(false); classicMatch_button.GetComponent <Animator>().SetTrigger(back_trigger); losAlamosMatch_button.GetComponent <Animator>().SetTrigger(back_trigger); chaturngaMatch_button.GetComponent <Animator>().SetTrigger(back_trigger); circledMatch_button.GetComponent <Animator>().SetTrigger(call_trigger); gameDescription_text.text = ChessConstants.CircledGameDescription; gameType = ChessGameType.circled; }
public bool SaveGame(string file_path, List <FigureMove> moves, ChessGameType gameType) { var sb = new StringBuilder(); sb.Append((int)gameType); sb.Append(";"); foreach (var move in moves) { sb.Append(((ChessLetter)move.from_x).ToString()); sb.Append(move.from_y.ToString()); sb.Append((ChessLetter)move.to_x).ToString(); sb.Append(move.to_y.ToString()); sb.Append(';'); } int k = file_path.Length - SaveFileExtention.Length; foreach (var char_symb in SaveFileExtention) { if (char_symb != file_path[k]) { file_path = file_path + SaveFileExtention; break; } k++; } try { var sw = File.CreateText(file_path); sw.Write(sb.ToString()); sw.Close(); } catch (Exception ex) { return(false); } return(true); }
public bool LoadGame(string filePath, out ChessGameType gameType, out List <BoardPosition> fromPositions, out List <BoardPosition> toPositions) { string start_data_str = null; gameType = ChessGameType.classic; fromPositions = new List <BoardPosition>(); toPositions = new List <BoardPosition>(); try { if (File.Exists(filePath)) { start_data_str = File.ReadAllText(filePath); } } catch (Exception ex) { return(false); } var start_data = start_data_str.Split(';'); gameType = (ChessGameType)int.Parse(start_data[0]); for (int i = 1; i < start_data.Length; i++) { if (!string.IsNullOrEmpty(start_data[i])) { BoardPosition from; BoardPosition to; UciConverter.GetBoardPositionsFromMoveCommand(start_data[i], out from, out to); fromPositions.Add(from); toPositions.Add(to); } } return(true); }
public IChessItemModel[,] FiguresPlacement(string short_fen, int size_x, int size_y, ChessGameType type) { var result = new IChessItemModel[size_x, size_y]; if (short_fen.Contains(" ")) { short_fen = short_fen.Split(' ')[0]; } string[] split = short_fen.Split('/'); int y = size_y - 1; int x = 0; foreach (var fen_item in split) { x = 0; bool skip_next = false; foreach (var char_item in fen_item) { if (skip_next) { skip_next = false; continue; } if (char.IsDigit(char_item)) { int count; if (x + 1 < fen_item.Length && char.IsDigit(fen_item[x + 1])) { count = int.Parse((fen_item[x] + fen_item[x + 1]).ToString()); x++; skip_next = true; } else { count = int.Parse(char_item.ToString()); } for (int i = 0; i < count; i++) { result[x, y] = new NullChessItemModel(new BoardPosition(x, y)); x++; } } else { var bp = new BoardPosition(x, y); ChessSide side; switch (type) { case ChessGameType.classic: side = char.IsUpper(char_item) ? ChessSide.white : ChessSide.black; switch (char.ToUpper(char_item)) { case 'P': result[x, y] = new ClassicPawnModel(side, bp); break; case 'R': result[x, y] = new ClassicRookModel(side, bp); break; case 'N': result[x, y] = new ClassicKnightModel(side, bp); break; case 'B': result[x, y] = new ClassicBishopModel(side, bp); break; case 'Q': result[x, y] = new ClassicQueenModel(side, bp); break; case 'K': result[x, y] = new ClassicKingModel(side, bp); break; default: throw new System.FormatException("FEN String Wrong Format!"); } break; case ChessGameType.los_alamos: side = char.IsUpper(char_item) ? ChessSide.white : ChessSide.black; switch (char.ToUpper(char_item)) { case 'P': result[x, y] = new LosAlamosPawnModel(side, bp); break; case 'R': result[x, y] = new LosAlamosRookModel(side, bp); break; case 'N': result[x, y] = new LosAlamosKnightModel(side, bp); break; case 'Q': result[x, y] = new LosAlamosQueenModel(side, bp); break; case 'K': result[x, y] = new LosAlamosKingModel(side, bp); break; default: throw new System.FormatException("FEN String Wrong Format!"); } break; case ChessGameType.chaturanga: if ("PRNQK".Contains(char_item.ToString())) { side = ChessSide.white; } else if ("prnqk".Contains(char_item.ToString())) { side = ChessSide.black; } else if ("UVWYZ".Contains(char_item.ToString())) { side = ChessSide.red; } else if ("uvwyz".Contains(char_item.ToString())) { side = ChessSide.green; } else { throw new System.NotImplementedException("Side was not implemented!"); } if ("PpUu".Contains(char_item.ToString())) { result[x, y] = new ChaturangaPawnModel(side, bp); } else if ("RrVv".Contains(char_item.ToString())) { result[x, y] = new ChaturangaRookModel(side, bp); } else if ("NnWw".Contains(char_item.ToString())) { result[x, y] = new ChaturangaKnightModel(side, bp); } else if ("QqYy".Contains(char_item.ToString())) { result[x, y] = new ChaturangaQueenModel(side, bp); } else if ("KkZz".Contains(char_item.ToString())) { result[x, y] = new ChaturangaKingModel(side, bp); } else { throw new System.FormatException("FEN String Wrong Format!"); } break; case ChessGameType.circled: side = char.IsUpper(char_item) ? ChessSide.white : ChessSide.black; switch (char.ToUpper(char_item)) { case 'P': result[x, y] = new CircledPawnModel(side, bp, Direction.right); break; case 'T': result[x, y] = new CircledPawnModel(side, bp, Direction.left); break; case 'R': result[x, y] = new CircledRookModel(side, bp); break; case 'N': result[x, y] = new CircledKnightModel(side, bp); break; case 'B': result[x, y] = new CircledBishopModel(side, bp); break; case 'Q': result[x, y] = new CircledQueenModel(side, bp); break; case 'K': result[x, y] = new CircledKingModel(side, bp); break; default: throw new System.FormatException("FEN String Wrong Format!"); } break; default: throw new System.NotImplementedException("FiguresPlacement Function Not Implemented Completely!"); } x++; } } y--; } return(result); }
public static IChessItemModel GetKilledChessItemFromMove(FigureMove move, ChessGameType chessType) { var side = (ChessSide)move.killed_side; var bp = new BoardPosition(move.killed_x, move.killed_y); switch (chessType) { case ChessGameType.classic: var type_classic = (ClassicChessItemType)move.killed_type; switch (type_classic) { case ClassicChessItemType.pawn: return(new ClassicPawnModel(side, bp, move.killed_steps)); case ClassicChessItemType.rook: return(new ClassicRookModel(side, bp, move.killed_steps)); case ClassicChessItemType.knight: return(new ClassicKnightModel(side, bp, move.killed_steps)); case ClassicChessItemType.bishop: return(new ClassicBishopModel(side, bp, move.killed_steps)); case ClassicChessItemType.queen: return(new ClassicQueenModel(side, bp, move.killed_steps)); case ClassicChessItemType.king: return(new ClassicKingModel(side, bp, move.killed_steps)); default: throw new ArgumentException("Figire Move Has Wrong Format!"); } case ChessGameType.los_alamos: var type_los_alamos = (LosAlamosChessItemType)move.killed_type; switch (type_los_alamos) { case LosAlamosChessItemType.pawn: return(new LosAlamosPawnModel(side, bp, move.killed_steps)); case LosAlamosChessItemType.rook: return(new LosAlamosRookModel(side, bp, move.killed_steps)); case LosAlamosChessItemType.knight: return(new LosAlamosKnightModel(side, bp, move.killed_steps)); case LosAlamosChessItemType.queen: return(new LosAlamosQueenModel(side, bp, move.killed_steps)); case LosAlamosChessItemType.king: return(new LosAlamosKingModel(side, bp, move.killed_steps)); default: throw new ArgumentException("Figire Move Has Wrong Format!"); } case ChessGameType.chaturanga: var type_chaturanga = (ChaturangaChessItemType)move.killed_type; switch (type_chaturanga) { case ChaturangaChessItemType.pawn: return(new ChaturangaPawnModel(side, bp, move.killed_steps)); case ChaturangaChessItemType.rook: return(new ChaturangaRookModel(side, bp, move.killed_steps)); case ChaturangaChessItemType.knight: return(new ChaturangaKnightModel(side, bp, move.killed_steps)); case ChaturangaChessItemType.king: return(new ChaturangaKingModel(side, bp, move.killed_steps)); default: throw new ArgumentException("Figire Move Has Wrong Format!"); } case ChessGameType.circled: var type_circled = (CircledChessItemType)move.killed_type; switch (type_circled) { case CircledChessItemType.pawn_left: return(new CircledPawnModel(side, bp, Direction.left, move.killed_steps)); case CircledChessItemType.pawn_right: return(new CircledPawnModel(side, bp, Direction.right, move.killed_steps)); case CircledChessItemType.rook: return(new CircledRookModel(side, bp, move.killed_steps)); case CircledChessItemType.knight: return(new CircledKnightModel(side, bp, move.killed_steps)); case CircledChessItemType.king: return(new CircledKingModel(side, bp, move.killed_steps)); default: throw new ArgumentException("Figire Move Has Wrong Format!"); } default: throw new NotImplementedException("GetKilledChessItemFromMove Not Implemented Completely!"); } throw new ArgumentException("Figire Move Has Wrong Format!"); }