private void CompleteTurn() { CheckSheikhPromotion(hoverBlock); turn = (turn == Piece.Team.Yellow) ? Piece.Team.Black : Piece.Team.Yellow; UpdateKillMovesList(); }
public void reset() { for (int i = 0; i < 64; i++) { this.pieces [i] = new Piece(); } for (int i = 0; i < 16; i++) { this.pieces [i] = new Piece(Piece.Type.PAWN, Piece.Team.WHITES); this.pieces [64 - 1 - i] = new Piece(Piece.Type.PAWN, Piece.Team.BLACKS); } this.pieces [0].type = Piece.Type.ROOK; this.pieces [1].type = Piece.Type.KNIGHT; this.pieces [2].type = Piece.Type.BISHOP; this.pieces [3].type = Piece.Type.QUEEN; this.pieces [4].type = Piece.Type.KING; this.pieces [5].type = Piece.Type.BISHOP; this.pieces [6].type = Piece.Type.KNIGHT; this.pieces [7].type = Piece.Type.ROOK; this.pieces [64 - 1 - 0].type = Piece.Type.ROOK; this.pieces [64 - 1 - 1].type = Piece.Type.KNIGHT; this.pieces [64 - 1 - 2].type = Piece.Type.BISHOP; this.pieces [64 - 1 - 3].type = Piece.Type.KING; this.pieces [64 - 1 - 4].type = Piece.Type.QUEEN; this.pieces [64 - 1 - 5].type = Piece.Type.BISHOP; this.pieces [64 - 1 - 6].type = Piece.Type.KNIGHT; this.pieces [64 - 1 - 7].type = Piece.Type.ROOK; this.current_team = Piece.Team.WHITES; this.game_events.Clear(); this.check_blacks = false; this.check_whites = false; this.win_blacks = false; this.win_whites = false; }
private void Start() { _turn = Piece.Team.None; _cam = FindObjectOfType <Camera>(); StartCoroutine(DelayStart()); }
// Locks mouse events in the Board and displays the winner team private void WinGame(Piece.Team team) { var message = $"Winner: {team.ToString()}"; _turn = Piece.Team.None; uiController.SendMessage("Message", ("CHECKMATE", team)); Debug.LogFormat(message); }
private bool handleEventCastle(int index_1, int index_2) { Piece.Team team_index_2 = this.pieces [index_1].team; Piece.Type type_index_2 = this.pieces [index_1].type; this.pieces [index_1].team = this.pieces [index_2].team; this.pieces [index_1].type = this.pieces [index_2].type; this.pieces [index_2].team = team_index_2; this.pieces [index_2].type = type_index_2; return(true); }
public void copy(Board source) { for (int i = 0; i < 64; i++) { this.pieces [i] = new Piece(source.getPiece(i).type, source.getPiece(i).team); } this.current_team = source.getCurrentTeam(); this.game_events.Clear(); this.check_blacks = source.isCheckBlacks(); this.check_whites = source.isCheckWhites(); this.win_blacks = source.hasWinBlacks(); this.win_whites = source.hasWinWhites(); }
private void GeneratePiece(Piece.Team team, Block block) { GameObject piecePrefab = (team == Piece.Team.Yellow) ? yellowPiecePrefab : blackPiecePrefab; GameObject go = Instantiate(piecePrefab) as GameObject; go.transform.SetParent(transform); Piece p = go.GetComponent <Piece>(); board[block.X, block.Y] = p; MovePiece(block); }
private void thinking() { this.index_board = 1; this.board_manager.get(0).copy(this.board_manager.get("default")); this.root.evaluated = false; this.root.children.Clear(); this.root_team = this.board_manager.get(0).getCurrentTeam(); if (!this.createTreeRecursively(this.root, Core.max_depth) || !this.evaluateTreeRecursively(this.root) || !this.setBestDecision()) { Debug.Log((this.is_stopped) ? "AI stopped thinking" : "AI failed"); } this.is_thinking = false; }
// Use this for initialization public Core(BoardManager board_manager, Referee referee) { this.board_evaluator = new BoardEvaluator(); this.board_manager = board_manager; this.referee = referee; this.root = new Node(); this.root.board = 0; this.board_manager.create(0); this.root_team = Piece.Team.NULL; this.index_board = 1; this.is_thinking = false; this.is_stopped = false; this.ai_thread = null; }
public void PlayRound(Piece.Team team) { status = Status.settingup; GameObject piecePrefab = (team == Piece.Team.Yellow) ? yellowPiecePrefab : blackPiecePrefab; rb = null; go = Instantiate(piecePrefab) as GameObject; go.transform.SetParent(transform); go.transform.position = transform.position + (Vector3.up * 6.0f); go.transform.rotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); status = Status.ready; }
private bool evaluateTreeRecursively(Node parent_node) { if (parent_node.children.Count == 0) { int number_moves = 0; for (int index_from = 0; index_from < 64; index_from++) { for (int index_to = 0; index_to < 64; index_to++) { if (this.is_stopped) { return(false); } if (index_to == index_from) { continue; } if (this.referee.move(index_from, index_to, parent_node.board)) { number_moves += 1; } } } parent_node.value = this.board_evaluator.evaluate(this.board_manager.get(parent_node.board), number_moves); return(true); } Piece.Team parent_team = this.board_manager.get(parent_node.board).getCurrentTeam(); foreach (Node child_node in parent_node.children) { if (this.is_stopped) { return(false); } if (!this.evaluateTreeRecursively(child_node)) { return(false); } if (!parent_node.evaluated || parent_team == this.root_team && child_node.value < parent_node.value || parent_team != this.root_team && child_node.value > parent_node.value) { parent_node.evaluated = true; parent_node.value = child_node.value; } } return(true); }
// Flips the camera and enables the other team to move public void SwitchTurn() { // Switch turn var lastTurn = _turn; _turn = _turn.Equals(Piece.Team.White) ? Piece.Team.Black : Piece.Team.White; _cam.SendMessage("Flip", _turn); // Verifies fo Check of Checkmate var kingObj = piecesManager.GetComponent <PiecesManager>().FindKing(_turn); var(check, checkmate) = kingObj.GetComponent <King>().IsCheck(); if (checkmate) { WinGame(lastTurn); } else if (check) { uiController.SendMessage("Message", ("CHECK", lastTurn)); } }
public Board() { this.pieces = new Piece[64]; for (int i = 0; i < 64; i++) { this.pieces [i] = new Piece(); } this.current_team = Piece.Team.WHITES; this.game_events = new Queue <GameEvent> (); this.event_to_handler = new Dictionary <GameEvent, Func <int, int, bool> > (); this.event_to_handler [GameEvent.MOVE] = this.handleEventMove; this.event_to_handler [GameEvent.ATTACK] = this.handleEventMove; this.event_to_handler [GameEvent.CASTLE_KINGSIDE] = this.handleEventCastle; this.event_to_handler [GameEvent.CASTLE_QUEENSIDE] = this.handleEventCastle; this.event_to_handler [GameEvent.CHECK] = this.handleEventCheck; this.event_to_handler [GameEvent.CHECKMATE] = this.handleEventCheckMate; this.check_blacks = false; this.check_whites = false; this.win_blacks = false; this.win_whites = false; }
private void ResetGame() { // remove all existing pieces for (int x = 0; x < boardSize; x++) { for (int y = 0; y < boardSize; y++) { Piece p = PieceForBlock(new Block(x, y)); if (p != null) { RemovePiece(p); board[x, y] = null; } } } // generate the board again GenerateBoard(); // yellow always goes first turn = Piece.Team.Yellow; }
private IEnumerator DelayStart() { yield return(new WaitForSeconds(2)); _turn = Piece.Team.White; }
void StartGame() { BilibiliLiveNetty.Instance.onDanmakuMessage = (uname, message) => { UnityTask.RunOnUIThread(() => { switch (state) { case State.Roll: switch (current) { case Piece.Team.Red: if (uname == redPlayer && message.ToLower() == "roll") { Roll(); accTime = 0; } break; case Piece.Team.Yellow: if (uname == yellowPlayer && message.ToLower() == "roll") { Roll(); accTime = 0; } break; case Piece.Team.Blue: if (uname == bluePlayer && message.ToLower() == "roll") { Roll(); accTime = 0; } break; case Piece.Team.Green: if (uname == greenPlayer && message.ToLower() == "roll") { Roll(); accTime = 0; } break; } break; case State.Select: switch (current) { case Piece.Team.Red: if (uname == redPlayer) { var flag = int.TryParse(message, out int index); if (flag) { Select(index); accTime = 0; } } break; case Piece.Team.Yellow: if (uname == yellowPlayer) { var flag = int.TryParse(message, out int index); if (flag) { Select(index); accTime = 0; } } break; case Piece.Team.Blue: if (uname == bluePlayer) { var flag = int.TryParse(message, out int index); if (flag) { Select(index); accTime = 0; } } break; case Piece.Team.Green: if (uname == greenPlayer) { var flag = int.TryParse(message, out int index); if (flag) { Select(index); accTime = 0; } } break; } break; } }); }; current = Piece.Team.Red; state = State.Roll; accTime = 0; Info.Instance.text.text = $"请红色玩家{redPlayer}投掷骰子,发送弹幕Roll进行Roll点"; SpeakInfo(); }
public void swapCurrentTeam() { this.current_team = (this.current_team == Piece.Team.BLACKS) ? Piece.Team.WHITES : Piece.Team.BLACKS; }
public void Roll() { if (state != State.Roll) { return; } point = Random.Range(1, 7); string str = null; switch (current) { case Piece.Team.Yellow: if (point != 6 && yellowControllablePiece.Count == 0) { str = $"Roll点为{point},请蓝色玩家{bluePlayer}投掷骰子,发送弹幕Roll进行Roll点"; state = State.Roll; current = Piece.Team.Blue; } else { str = $"Roll点为{point},请黄色玩家{yellowPlayer}选择飞机或起飞: "; state = State.Select; if (point == 6 && yellowControllablePiece.Count < yellowHomeCells.Count) { str += "0-起飞,"; } foreach (var piece in yellowControllablePiece) { str += piece.index + ","; } } break; case Piece.Team.Blue: if (point != 6 && blueControllablePiece.Count == 0) { str = $"Roll点为{point},请绿色玩家{greenPlayer}投掷骰子,发送弹幕Roll进行Roll点"; state = State.Roll; current = Piece.Team.Green; } else { str = $"Roll点为{point},请蓝色玩家{bluePlayer}选择飞机或起飞: "; state = State.Select; if (point == 6 && blueControllablePiece.Count < blueHomeCells.Count) { str += "0-起飞,"; } foreach (var piece in blueControllablePiece) { str += piece.index + ","; } } break; case Piece.Team.Green: if (point != 6 && greenControllablePiece.Count == 0) { str = $"Roll点为{point},请红色玩家{redPlayer}投掷骰子,发送弹幕Roll进行Roll点"; state = State.Roll; current = Piece.Team.Red; } else { str = $"Roll点为{point},请绿色玩家{greenPlayer}选择飞机或起飞: "; state = State.Select; if (point == 6 && greenControllablePiece.Count < greenHomeCells.Count) { str += "0-起飞,"; } foreach (var piece in greenControllablePiece) { str += piece.index + ","; } } break; case Piece.Team.Red: if (point != 6 && redControllablePiece.Count == 0) { str = $"Roll点为{point},请黄色玩家{yellowPlayer}投掷骰子,发送弹幕Roll进行Roll点"; state = State.Roll; current = Piece.Team.Yellow; } else { str = $"Roll点为{point},请红色玩家{redPlayer}选择飞机或起飞: "; state = State.Select; if (point == 6 && redControllablePiece.Count < redHomeCells.Count) { str += "0-起飞,"; } foreach (var piece in redControllablePiece) { str += piece.index + ","; } } break; } Info.Instance.text.text = str; SpeakInfo(); }
public void Select(int index) { if (state != State.Select) { return; } string str = null; switch (current) { case Piece.Team.Yellow: if (index == 0 && point == 6 && yellowControllablePiece.Count < yellowHomeCells.Count) { foreach (var homeCell in yellowHomeCells) { var piece = homeCell.piece; if (piece) { piece.transform.position = yellowStart.transform.position; piece.cell = yellowStart; yellowControllablePiece.Add(homeCell.piece); homeCell.piece = null; break; } } str = $"请黄色玩家{yellowPlayer}继续投掷骰子,发送弹幕Roll进行Roll点"; state = State.Roll; } else { foreach (var piece in yellowControllablePiece) { if (piece.index == index) { if (point != 6) { current = Piece.Team.Blue; str = $"请蓝色玩家{bluePlayer}投掷骰子,发送弹幕Roll进行Roll点"; } else { str = $"请黄色玩家{yellowPlayer}继续投掷骰子,发送弹幕Roll进行Roll点"; } state = State.Roll; piece.Move(point); break; } } } break; case Piece.Team.Blue: if (index == 0 && point == 6 && blueControllablePiece.Count < blueHomeCells.Count) { foreach (var homeCell in blueHomeCells) { var piece = homeCell.piece; if (piece) { piece.transform.position = blueStart.transform.position; piece.cell = blueStart; blueControllablePiece.Add(homeCell.piece); homeCell.piece = null; break; } } str = $"请蓝色玩家{bluePlayer}继续投掷骰子,发送弹幕Roll进行Roll点"; state = State.Roll; } else { foreach (var piece in blueControllablePiece) { if (piece.index == index) { if (point != 6) { current = Piece.Team.Green; str = $"请绿色玩家{greenPlayer}投掷骰子,发送弹幕Roll进行Roll点"; } else { str = $"请蓝色玩家{bluePlayer}继续投掷骰子,发送弹幕Roll进行Roll点"; } state = State.Roll; piece.Move(point); break; } } } break; case Piece.Team.Green: if (index == 0 && point == 6 && greenControllablePiece.Count < greenHomeCells.Count) { foreach (var homeCell in greenHomeCells) { var piece = homeCell.piece; if (piece) { piece.transform.position = greenStart.transform.position; piece.cell = greenStart; greenControllablePiece.Add(homeCell.piece); homeCell.piece = null; break; } } str = $"请绿色玩家{greenPlayer}继续投掷骰子,发送弹幕Roll进行Roll点"; state = State.Roll; } else { foreach (var piece in greenControllablePiece) { if (piece.index == index) { if (point != 6) { current = Piece.Team.Red; str = $"请红色玩家{redPlayer}投掷骰子,发送弹幕Roll进行Roll点"; } else { str = $"请绿色玩家{greenPlayer}继续投掷骰子,发送弹幕Roll进行Roll点"; } state = State.Roll; piece.Move(point); break; } } } break; case Piece.Team.Red: if (index == 0 && point == 6 && redControllablePiece.Count < redHomeCells.Count) { foreach (var homeCell in redHomeCells) { var piece = homeCell.piece; if (piece) { piece.transform.position = redStart.transform.position; piece.cell = redStart; redControllablePiece.Add(homeCell.piece); homeCell.piece = null; break; } } str = $"请红色玩家{redPlayer}继续投掷骰子,发送弹幕Roll进行Roll点"; state = State.Roll; } else { foreach (var piece in redControllablePiece) { if (piece.index == index) { if (point != 6) { current = Piece.Team.Yellow; str = $"请黄色玩家{yellowPlayer}投掷骰子,发送弹幕Roll进行Roll点"; } else { str = $"请红色玩家{redPlayer}继续投掷骰子,发送弹幕Roll进行Roll点"; } state = State.Roll; piece.Move(point); break; } } } break; } Info.Instance.text.text = str; SpeakInfo(); }
// Change target poss and focal point base on turn public void Flip(Piece.Team team) { _target = team.Equals(Piece.Team.Black) ? possBlack : possWhite; _focalPoint = team.Equals(Piece.Team.Black) ? focalBlack : focalWhite; }
public void PawnPromotion(Piece.Team team) { uiController.SendMessage("Message", ("Pawn Promotion", team)); SwitchTurn(); }