private void PlacePieces(ChessMoveResult boardData, bool flipped) { foreach (var piece in boardData.PieceInfos) { string colorChar = piece.Color == Core.DTOs.Chess.Color.White ? "w" : "b"; string typeChar = GetPieceTypeString(piece); string imagePath = $"{colorChar}_{piece.Type.ToString().ToLower()}_svg_withShadow.png"; Image i = new Image { Stretch = Stretch.Uniform, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Source = new BitmapImage(new Uri($"ms-appx:///Assets/{imagePath}")) }; int row = !flipped ? piece.Row : 7 - piece.Row; int column = !flipped ? piece.Column : 7 - piece.Column; i.SetValue(Grid.RowProperty, row); i.SetValue(Grid.ColumnProperty, column); i.IsHitTestVisible = false; BoardContainer.Children.Add(i); } }
public void MoveDelayed(ChessDelayedAction action) { if (Logic.Turn != action.Color) { return; } var player = Sides[(int)action.Color].GetPlayer(); if (player == null) { QuitDelayed(action.Color); return; } var result = Logic.DoMove(action.Color, action.From, action.To); if (result < ChessMoveResult.NoMoveResult) { SendMoveResponse(player, result); return; } MoveResult = result; FinalizeWeenieMove(result); }
public override int GetHashCode() { int hash = 1; if (source_ != null) { hash ^= Source.GetHashCode(); } if (target_ != null) { hash ^= Target.GetHashCode(); } if (ChessMoveResult != 0) { hash ^= ChessMoveResult.GetHashCode(); } if (Counter != 0) { hash ^= Counter.GetHashCode(); } if (operator_ != null) { hash ^= Operator.GetHashCode(); } return(hash); }
public void FinishAiMove() { Debug.Assert(AiState == ChessAiState.WaitingForFinish); AiState = ChessAiState.None; var result = AiFuture; MoveResult = result.Result; if (MoveResult == ChessMoveResult.NoMoveResult) { var color = Chess.InverseColor(Logic.Turn); var side = Sides[(int)color]; var opSide = Sides[(int)Logic.Turn]; // checkmate if (Logic.InCheckmate(color, true)) { Finish((int)Logic.Turn); } // stalemate else { side.Stalemate = true; if (opSide.Stalemate) { Finish(Chess.ChessWinnerStalemate); } else { SendOpponentStalemate(opSide.GetPlayer(), side.Color, true); } } } else { FinalizeWeenieMove(result.Result); } //Console.WriteLine($"Calculated Chess AI move in {result.ProfilingTime} ms with {result.ProfilingCounter} minimax calculations."); }
IEnumerator TweenMoveChess(ChessHeroData heroChoosed, ChessPoint moveToPoint, ChessMoveResult result, ChessMoveData moveData) { m_MyChessIsMoving = true; //if((ChessMoveResult.CANNOT_MOVE == result && moveData.crashType > 0) || (ChessMoveResult.CAN_MOVE == result && moveData.crashType == 0)) //{ Push("_cleanArrow"); m_lastPath = moveData.points; float dur = 0.2f / moveData.points.Length; for (int i = 1; i < moveData.points.Length; i++) { ShowChessMoveTo(heroChoosed.point, moveData.points[i]); ChessMoveTo(heroChoosed, moveData.points[i]); yield return(new WaitForSeconds(dur)); } //加入历史走子 App.Package.ChessGame.ChessHistorySteps.Insert(0, App.Package.ChessGame.BuildHistoryStep( App.Package.ChessGame.GameRoundCounter, heroChoosed, moveToPoint, App.Package.ChessGame.BuildChessDataPathFromPoints(moveData.points), (int)result ) ); Push("_updateHistory"); heroChoosed.point = moveToPoint; m_MyChessIsMoving = false; NextGameRound(); //} /*else * { * ChessDataHasProblem(); * }*/ }
public void FinalizeWeenieMove(ChessMoveResult result) { var move = Logic.GetLastMove(); Log.Add(move); // need to use destination coordinate as Logic has already moved the piece var piece = Logic.GetPiece(move.To); if (result.HasFlag(ChessMoveResult.OKMoveToEmptySquare)) { MoveWeeniePiece(piece); var flags = move.Flags; if ((flags & (ChessMoveFlag.KingSideCastle | ChessMoveFlag.QueenSideCastle)) != 0) { var castlingTo = new ChessPieceCoord(move.To); if (flags.HasFlag(ChessMoveFlag.KingSideCastle)) { castlingTo.MoveOffset(-1, 0); } if (flags.HasFlag(ChessMoveFlag.QueenSideCastle)) { castlingTo.MoveOffset(1, 0); } var rookPiece = Logic.GetPiece(castlingTo); Debug.Assert(rookPiece != null); MoveWeeniePiece(rookPiece); } } else if (result.HasFlag(ChessMoveResult.OKMoveToOccupiedSquare)) { AttackWeeniePiece(piece, move.CapturedGuid); } }
public override void Unpack(BinaryReader reader) { base.Unpack(reader); IdGame = reader.ReadUInt32(); MoveResult = (ChessMoveResult)reader.ReadInt32(); }
IEnumerator TweenMoveChessAndBeat(ChessHeroData heroChoosed, ChessHeroData hero, ChessMoveResult resultR, ChessMoveData moveData) { m_MyChessIsMoving = true; if ((resultR == ChessMoveResult.CANNOT_MOVE && moveData.crashType <= 0) || (resultR == ChessMoveResult.CAN_MOVE && moveData.crashType > 0)) { ChessDataHasProblem(); } else { if (moveData.crashType > 0) { App.Package.ChessGame.MyselfChooseChessId = hero.id; Debugger.Warn("ChessHeroItem Cant MoveTo " + hero.point.ToString() + " : " + moveData.crashType); m_MyChessIsMoving = false; } else { Push("_cleanArrow"); m_lastPath = moveData.points; ChessMoveResult result = resultR;//ChessAgainst.ChessCanBeat(heroChoosed, hero); float dur = 0.4f / moveData.points.Length; for (int i = 1; i < moveData.points.Length - 1; i++) { ShowChessMoveTo(heroChoosed.point, moveData.points[i]); ChessMoveTo(heroChoosed, moveData.points[i]); yield return(new WaitForSeconds(dur)); } //加入历史走子 App.Package.ChessGame.ChessHistorySteps.Insert(0, App.Package.ChessGame.BuildHistoryStep( App.Package.ChessGame.GameRoundCounter, heroChoosed, hero, App.Package.ChessGame.BuildChessDataPathFromPoints(moveData.points), (int)result ) ); Push("_updateHistory"); switch (result) { case ChessMoveResult.LOSE: heroChoosed.state = ChessHeroState.Died; heroChoosed.gameObject.SetActive(false); break; case ChessMoveResult.TIE: heroChoosed.state = ChessHeroState.Died; heroChoosed.gameObject.SetActive(false); hero.state = ChessHeroState.Died; hero.gameObject.SetActive(false); break; case ChessMoveResult.WIN: hero.state = ChessHeroState.Died; hero.gameObject.SetActive(false); break; } ShowChessMoveTo(heroChoosed.point, moveData.points[moveData.points.Length - 1]); ChessMoveTo(heroChoosed, moveData.points[moveData.points.Length - 1]); if (result > 0) { //UIWChessHeroItem uiChess = heroChoosed.gameObject.GetComponent<UIWChessHeroItem>(); //uiChess.isChoosed = true; //uiChess.UpdateView(); } else { //App.Package.ChessGame.MyselfChooseChessId = -1; } int cid = -1; bool resultS; if (heroChoosed.group == ChessHeroGroup.Myself) { cid = heroChoosed.realChessType; resultS = result == ChessMoveResult.WIN; if (cid > 0 && cid < 11 && cid != 1) { m_roundOver.SetState(cid, resultS); } } else { cid = hero.realChessType; resultS = result == ChessMoveResult.WIN; if (cid > 0 && cid < 11 && cid != 1) { switch (result) { case ChessMoveResult.WIN: case ChessMoveResult.TIE: m_roundOver.SetState(cid, false); break; case ChessMoveResult.LOSE: m_roundOver.SetState(cid, true); break; } } } App.Package.ChessGame.MyselfChooseChessId = heroChoosed.id; Push("_chessHeroChoosed", heroChoosed.id); m_MyChessIsMoving = false; NextGameRound(); } } }
private void OnChessHeroClick(object content)//吃子移动 { if (App.Package.ChessGame.IsGameStart) { if (!App.Package.ChessGame.IsMyRound) { Common.UI.OpenTips("敌方回合,无法行动"); return; } if (m_MyChessIsMoving) { return; //正在移动 } Intent intent = (Intent)content; int id = (int)intent.Value("id"); GameObject go = (GameObject)intent.Value("gameObject"); ChessHeroData hero = App.Package.ChessGame.GetChessHeroDataById(id); ChessHeroGroup group = hero.group; Push("_chessHeroChoosed", id); //明棋模式提醒 if (group == ChessHeroGroup.Myself) { for (int i = 0; i < App.Package.ChessGame.ChessDataIds.Count; i++) { int chessId = App.Package.ChessGame.ChessDataIds[i]; ChessHeroData heroPre = App.Package.ChessGame.GetChessHeroDataById(chessId); if (heroPre.group == ChessHeroGroup.Myself) { continue; } UIWChessHeroItem uiChess = heroPre.gameObject.GetComponent <UIWChessHeroItem>(); uiChess.willLose.SetActive(false); uiChess.willWin.SetActive(false); uiChess.willTie.SetActive(false); if (heroPre.heroTypeId > -1 && ChessAgainst.ChessHeroCanMove(hero)) { ChessMoveResult result = ChessAgainst.ChessCanBeat(hero, heroPre); switch (result) { case ChessMoveResult.LOSE: uiChess.willLose.SetActive(true); break; case ChessMoveResult.TIE: uiChess.willTie.SetActive(true); break; case ChessMoveResult.WIN: uiChess.willWin.SetActive(true); break; } } } } else { for (int i = 0; i < App.Package.ChessGame.ChessDataIds.Count; i++) { int chessId = App.Package.ChessGame.ChessDataIds[i]; ChessHeroData heroPre = App.Package.ChessGame.GetChessHeroDataById(chessId); if (heroPre.group == ChessHeroGroup.Myself) { continue; } UIWChessHeroItem uiChess = heroPre.gameObject.GetComponent <UIWChessHeroItem>(); uiChess.willLose.SetActive(false); uiChess.willWin.SetActive(false); uiChess.willTie.SetActive(false); } } if (App.Package.ChessGame.MyselfChooseChessId > -1) { ChessHeroData heroChoosed = App.Package.ChessGame.GetChessHeroDataById(App.Package.ChessGame.MyselfChooseChessId); if (heroChoosed.group == ChessHeroGroup.Myself && group != ChessHeroGroup.Myself) //之前有选择自己,当前非己方的棋 { if (App.Package.ChessGame.IsGameStart) //游戏开始了之后才能走并吃子 { if (ChessAgainst.IsBarrack(hero.point) && hero.point.y > 5) //敌方的军营 { Common.UI.OpenTips("敌军在行营里,不要浪啊~"); } else { if (ChessAgainst.IsStronghold(heroChoosed.point)) { Common.UI.OpenTips("大本营的棋子无法移动!"); } else { ChessMoveData moveData = ChessAgainst.ChessHeroCanMoveTo(heroChoosed, hero.point); if (moveData.crashType > 0) { if (moveData.crashType == 1) { switch (moveData.crashHero.heroTypeId) { case 0: Common.UI.OpenTips("地雷无法移动!"); break; case 11: Common.UI.OpenTips("军旗无法移动!"); break; default: Common.UI.OpenTips("嗷!走不过去啊!"); break; } } else { Common.UI.OpenTips("嗷!走不过去啊!"); } } else { RequestToMove(heroChoosed, hero.point, hero, moveData); } } } } } } App.Package.ChessGame.MyselfChooseChessId = id; } else { if (App.Package.ChessGame.IsReadyGame) { Common.UI.OpenTips("比赛还没开始哦,不要心急"); } else { Common.UI.OpenTips("赶紧布兵吧!你还没有准备呢\n长按拖动可以交换棋子!"); } } }
/// <summary> /// 走子情况 /// </summary> void OnReceiveChessMove(object data) { ChessMovePush push = (ChessMovePush)data; ChessData source = push.Source; ChessData target = push.Target; ChessMoveResult result = (ChessMoveResult)push.ChessMoveResult; ChessHeroData sourceReal = App.Package.ChessGame.GetChessHeroDataByRemoteId(source.ChessRemoteId); //强制回合同步 App.Package.ChessGame.GameRoundCounter = push.Counter - 1; if (target != null) { ChessHeroData targetReal = App.Package.ChessGame.GetChessHeroDataByRemoteId(target.ChessRemoteId); if (sourceReal == null || (targetReal == null && result != ChessMoveResult.CAN_MOVE && result != ChessMoveResult.CANNOT_MOVE) || push.Counter != App.Package.ChessGame.GameRoundCounter + 1) { ChessDataHasProblem(); return; } ChessHeroData fake = ChessDataToChessHeroData(target, true); if (targetReal != null) { fake = targetReal; } ChessMoveData moveData = ChessAgainst.ChessHeroCanMoveTo(sourceReal, fake.point); switch (result) { case ChessMoveResult.LOSE: fake.heroTypeId = 12; StartCoroutine(TweenMoveChessAndBeat(sourceReal, fake, result, moveData)); break; case ChessMoveResult.WIN: fake.heroTypeId = -2; StartCoroutine(TweenMoveChessAndBeat(sourceReal, fake, result, moveData)); break; case ChessMoveResult.TIE: fake.heroTypeId = -3; StartCoroutine(TweenMoveChessAndBeat(sourceReal, fake, result, moveData)); break; case ChessMoveResult.CAN_MOVE: StartCoroutine(TweenMoveChess(sourceReal, fake.point, result, moveData)); break; case ChessMoveResult.CANNOT_MOVE: break; } } else { NextGameRound(); if (source.Belong == App.Package.Player.GetBelong()) { Common.UI.OpenTips("超时跳过"); } else { Common.UI.OpenTips("敌方超时跳过"); } Debugger.Error("skip"); } }
public GameEventMoveResponse(Session session, ObjectGuid boardGuid, ChessMoveResult result) : base(GameEventType.MoveResponse, GameMessageGroup.UIQueue, session) { Writer.Write(boardGuid.Full); Writer.Write((int)result); }
public void SetResult(ChessMoveResult result, ChessPieceCoord from, ChessPieceCoord to) { Result = result; From = from; To = to; }
public void SendMoveResponse(Player player, ChessMoveResult result) { player.Session.Network.EnqueueSend(new GameEventMoveResponse(player.Session, ChessBoard.Guid, result)); }