public override void ChooseMovesAsPBar(MoveResult moveResult) { Move move = moveResult.Move; LogDebugMessage("*** ANTAGONIST (PBar = {0}) ***", move.pBar); LogDebugMessage("Slack: {0}", moveResult.Slack); double valueOfMove = ScenarioValueFunctions.ClearRunAtBaseScenarioValueFunction.Evaluate(moveResult.Slack); LogDebugMessage("Value of move: {0}", valueOfMove); // Defend against an enemy attack on your base: for (int tankNumber = 0; tankNumber < Constants.TANKS_PER_PLAYER; tankNumber++) { LogDebugMessage("Tank number: {0}", tankNumber); TankActionRecommendation recommendation = moveResult.GetRecommendedTankActionsByPlayerAndTankNumber(move.pBar, tankNumber); if (recommendation.IsAMoveRecommended) { TankSituation tankSituation = GameSituation.GetTankSituationByPlayerAndTankNumber(move.pBar, tankNumber); TankAction recommendedTankAction = recommendation.RecommendedTankAction; LogDebugMessage("Recommended tank action: {0}", recommendedTankAction); tankSituation.AdjustTankActionValue(recommendedTankAction, valueOfMove); } else { LogDebugMessage("No moves recommended"); } } }
private void RpcSetGameSituation(SerializedGameSituation serializedGameSituation) { if (!isLocalPlayer) { return; } GameSituation gameSituation = SerializedGameSituation.Deserealize(serializedGameSituation); clientManager.SetGameSituation(gameSituation); if (gameSituation.GameStatus == GameStatus.OpponentExits) { clientManager.Block(true, PlayerColor.White); clientManager.Block(true, PlayerColor.Black); return; } if ((playerColor == PlayerColor.White) && (gameSituation.IsWhiteMoving)) { clientManager.Block(false, PlayerColor.White); } else if ((playerColor == PlayerColor.Black) && (!gameSituation.IsWhiteMoving)) { clientManager.Block(false, PlayerColor.Black); } else { clientManager.Block(true, playerColor); } }
public static bool DecisionNeeded(this GameBoard board, GameSituation situation) { var legalEndpoints = board.GetLegalEndpoints(situation.BoardLocation, situation.Spin); bool win = legalEndpoints.ResultsInWin(); return(!win && legalEndpoints.Count() > 1); }
public void SetGameSituation(GameSituation gameSituation) { if (gameSituation.GameStatus == GameStatus.OpponentExits) { if (endGame) { return; } endGame = true; NotifyOpponentExits(); return; } if (gameSituation.GameStatus == GameStatus.Checkmate) { endGame = true; if (gameSituation.IsWhiteMoving) { NotifyCheckMateWhite(); } else { NotifyCheckMateBlack(); } } board.SetGameSituation(gameSituation); }
public void InitializeBoard(GameSituation gameSituation) { if (pieces.Values.Count != 0) { foreach (GameObject piece in pieces.Values) { Destroy(piece); } pieces.Clear(); } for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { Cell pieceCell = new Cell(i, j); var piece = gameSituation.PiecesLocation[i, j]; if (piece.Item1 == ChessPieceType.None) { continue; } GameObject newPiece = CreatePiece(piece.Item1, piece.Item2, pieceCell); pieces.Add(pieceCell, newPiece); Piece pieceScript = newPiece.GetComponent <Piece>(); if (gameSituation.AllowedMoves.ContainsKey(pieceCell)) { pieceScript.AllowedMoves = gameSituation.AllowedMoves[pieceCell]; } else { pieceScript.AllowedMoves = new HashSet <Cell>(); } } } }
public override void ChooseMovesAsP(MoveResult moveResult) { Move move = moveResult.Move; LogDebugMessage("*** PROTAGONIST (P = {0}) ***", move.p); LogDebugMessage("Slack: {0}", moveResult.Slack); double valueOfMove = ScenarioValueFunctions.ClearRunAtBaseScenarioValueFunction.Evaluate(moveResult.Slack); LogDebugMessage("Value of move: {0}", valueOfMove); // Attack the enemy base: LogDebugMessage("Tank number: {0}", move.i); TankActionRecommendation recommendation = moveResult.GetRecommendedTankActionsByPlayerAndTankNumber(move.p, move.i); if (recommendation.IsAMoveRecommended) { TankSituation tankSituation = GameSituation.GetTankSituationByPlayerAndTankNumber(move.p, move.i); TankAction recommendedTankAction = recommendation.RecommendedTankAction; LogDebugMessage("Recommended tank action: {0}", recommendedTankAction); tankSituation.AdjustTankActionValue(recommendedTankAction, valueOfMove); } else { LogDebugMessage("No moves recommended"); } }
private void Move(PlayerAct playerAct) { GameSituation gameSituation = chessGame.MakeMove(playerAct.From, playerAct.To); whitePlayer.SetGameSituation(gameSituation); blackPlayer.SetGameSituation(gameSituation); }
public void SetGameSituation(GameSituation gameSituation) { if (((gameSituation.IsWhiteMoving) && (playerColor == PlayerColor.White)) || ((!gameSituation.IsWhiteMoving) && (playerColor == PlayerColor.Black))) { uciAdapter.SetGameSituation(gameSituation); } }
public int GetMove(GameSituation situation) { if (!situation.LegalMoves.Contains(situation.BoardLocation + situation.Spin)) { throw new InvalidOperationException(); } return(situation.BoardLocation + situation.Spin); }
private bool TrySetBestMoveSoFar(GameState currGameState, GameSituation gameSituation) { TankActionSet actionSet = gameSituation.GenerateTankActions(YourPlayerIndex, currGameState.Tick); Coordinator.SetBestMoveSoFar(actionSet); return(true); }
public void SetGameSituation(GameSituation gameSituation) { if (state != State.Ready) { throw new System.Exception("Движок не готов к ходу"); } SendCommand("position fen " + TranslateGameSituationToFen(gameSituation)); state = State.Run; SendCommand("go"); }
public int GetMove(GameSituation situation) { var bestOption = _paths.FindClosestToEnd(situation.LegalMoves); //var bestOptionDistance = _paths[bestOption]; //var maxOptionDistance = _paths[situation.LegalMoves.Max()]; //if (bestOptionDistance < maxOptionDistance) // Console.WriteLine($"*** Greedy option not the best for {situation.BoardLocation}-{situation.Spin}"); return(bestOption); }
public int GetMove(GameSituation situation) { var result = _rules.Process(situation.BoardLocation, situation.Spin); if (!situation.LegalMoves.Contains(result)) { throw new InvalidOperationException($"Illegal result returned {result}. Legal options: {string.Join(",", situation.LegalMoves)}"); } return(result); }
public void SetGameSituation(GameSituation gameSituation) { PlayerColor myColor = gameSituation.IsWhiteMoving ? PlayerColor.White : PlayerColor.Black; for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { Cell cell = new Cell(i, j); var piece = gameSituation.PiecesLocation[i, j]; if (pieces.ContainsKey(cell)) { GameObject pieceObject = pieces[cell]; Piece pieceScriptObject = pieceObject.GetComponent <Piece>(); if ((pieceScriptObject.PlayerColor == piece.Item2) && (pieceScriptObject.ChessPieceType == piece.Item1)) { if (gameSituation.AllowedMoves.ContainsKey(cell)) { pieceScriptObject.AllowedMoves = gameSituation.AllowedMoves[cell]; } else { pieceScriptObject.AllowedMoves = new HashSet <Cell>(); } continue; } else { pieces.Remove(cell); Destroy(pieceObject); } } if (!pieces.ContainsKey(cell)) { if (piece.Item1 == ChessPieceType.None) { continue; } GameObject pieceObject = CreatePiece(piece.Item1, piece.Item2, cell); Piece pieceScriptObject = pieceObject.GetComponent <Piece>(); if (gameSituation.AllowedMoves.ContainsKey(cell)) { pieceScriptObject.AllowedMoves = gameSituation.AllowedMoves[cell]; } else { pieceScriptObject.AllowedMoves = new HashSet <Cell>(); } pieces.Add(cell, pieceObject); continue; } } } }
/// <summary> /// 获得开局时的决策 /// </summary> /// <param name="ThisChessBoard">当前棋盘状态</param> /// <returns>下一步决策</returns> public QuoridorAction GetFormulaePolicy(ChessBoard ThisChessBoard) { QuoridorAction NextPolicy = new QuoridorAction(NowAction.Action_Wait, new Point(-1, -1)); string CBString = ChessBoardToString(ThisChessBoard); string LString = ChessBoardLocationToString(ThisChessBoard, PolicyPlayer); if (CBFormulaeList.ContainsKey(CBString))//检测棋盘定式库 { NextPolicy = CBFormulaeList[CBString]; if (NextPolicy.SkipChessScore == 999) { NowGameSituation = GameSituation.PreviousSituation; } } else if (LocationFormulaeList.ContainsKey(LString))//检测位置定式库 { NextPolicy = LocationFormulaeList[LString]; if (NextPolicy.SkipChessScore == 999) { NowGameSituation = GameSituation.PreviousSituation; } } else//直走或者最短路径走 { Point PlayerLocation = ThisChessBoard.Player1Location; if (PolicyPlayer == EnumNowPlayer.Player2) { PlayerLocation = ThisChessBoard.Player2Location; NextPolicy.PlayerAction = NowAction.Action_Move_Player2; NextPolicy.ActionPoint = new Point(PlayerLocation.X - 1, PlayerLocation.Y); } else { NextPolicy.PlayerAction = NowAction.Action_Move_Player1; NextPolicy.ActionPoint = new Point(PlayerLocation.X + 1, PlayerLocation.Y); } string ErrorHint = ""; ErrorHint = NowEvalution.QuoridorRule.CheckMove_NoChange(ThisChessBoard , NextPolicy.ActionPoint.X, NextPolicy.ActionPoint.Y, NextPolicy.PlayerAction); if (ErrorHint != "OK")//只能最短路径走 { List <QuoridorAction> MoveActionList = new List <QuoridorAction>(); NowEvalution.AddMoveAction(ref MoveActionList, ThisChessBoard, PolicyPlayer, PlayerLocation); NowEvalution.ActionListEvaluation(ThisChessBoard, ref MoveActionList, PolicyPlayer, 0, 0, -50); NextPolicy = MoveActionList[0]; } if (CheckInitialSituationEnd(ThisChessBoard)) { NowGameSituation = GameSituation.PreviousSituation; } } FormulaePolicyNum++; return(NextPolicy); }
private void EvaluateDodgeBulletScenario(GameState currGameState, GameSituation gameSituation) { Scenario scenario = new ScenarioToDodgeABullet(currGameState, gameSituation, YourPlayerIndex); ScenarioEvaluator.EvaluateScenario(scenario); /* NB: There is no need to choose moves as well. * This will already be done while evaluating the scenario, * since there aren't alternative strategies to choose from, * so no MinMax is needed. */ }
public ServerManager(IPlayer whitePlayer, IPlayer blackPlayer) { this.whitePlayer = whitePlayer; this.blackPlayer = blackPlayer; whitePlayer.PlayerActedEvent += SetPlayerAct; blackPlayer.PlayerActedEvent += SetPlayerAct; chessGame = new ChessGame(); GameSituation gameSituation = chessGame.InitializeBoard(); whitePlayer.SetGameSituation(gameSituation); blackPlayer.SetGameSituation(gameSituation); }
private void Awake() { GamePhase = GameSituation.setPieces; numOfDeployedBluePieces = 0; unityObjects = new Dictionary <string, GameObject>(); GameObject[] objects = GameObject.FindGameObjectsWithTag("unityObjects"); foreach (GameObject go in objects) { unityObjects.Add(go.name, go); //print("go.name= " + go.name); } print("Amount of Object is = " + unityObjects.Count); InitializeEnemy(); listener = new Listener(); rooms = new List <string>(); }
public void SetGameSituation(GameSituation gameSituation) { clientManager.SetGameSituation(gameSituation); if ((playerColor == PlayerColor.White) && (gameSituation.IsWhiteMoving)) { clientManager.Block(false, PlayerColor.White); } else if ((playerColor == PlayerColor.Black) && (!gameSituation.IsWhiteMoving)) { clientManager.Block(false, PlayerColor.Black); } else { clientManager.Block(true, PlayerColor.White); clientManager.Block(true, PlayerColor.Black); } }
private void Exit(PlayerAct playerAct) { IPlayer player; if (playerAct.PlayerColor == PlayerColor.White) { player = blackPlayer; } else { player = whitePlayer; } GameSituation gameSituation = new GameSituation { GameStatus = GameStatus.OpponentExits }; player.SetGameSituation(gameSituation); }
private void Say(GameSituation status) { switch (status) { case GameSituation.Idle: Console.ForegroundColor = ConsoleColor.White; break; case GameSituation.ActiveTest: Console.ForegroundColor = ConsoleColor.Yellow; break; case GameSituation.InactiveTest: Console.ForegroundColor = ConsoleColor.Blue; break; case GameSituation.AnswerTest: Console.ForegroundColor = ConsoleColor.Green; break; case GameSituation.ActiveNumeric: Console.ForegroundColor = ConsoleColor.Yellow; break; case GameSituation.InactiveNumeric: Console.ForegroundColor = ConsoleColor.Blue; break; case GameSituation.AnswerNumeric: Console.ForegroundColor = ConsoleColor.Green; break; } Console.Write("[Состояние]: "); Console.WriteLine(status); Console.ResetColor(); }
public void EnterFreeMode() { Situation = GameSituation.Free; ZonesParentGO.SetActive (false); if (currentBuildingPrototype != null) { Destroy(currentBuildingPrototype.MainTransform.gameObject); currentBuildingPrototype = null; } }
public void EnterBuildingMode() { UnselectAllUnits(); Situation = GameSituation.Building; var go = (GameObject)Instantiate(Resources.Load("TownHallBuilding")); var bm = go.GetComponent<BuildingManager>(); bm.Data = new BuildingData(); bm.Data.Size = new Vector2(5, 5); bm.Data.State = BuildingState.Prototype; currentBuildingPrototype = bm; }
public ScenarioToDodgeABullet(GameState gameState, GameSituation gameSituation, int yourPlayerIndex) : base(gameState, gameSituation) { YourPlayerIndex = yourPlayerIndex; }
public GameResult(GameSituation situation, GameModel model) { Situation = situation; Model = model; }
protected override void ChooseMoves() { bool moveSet = false; try { // TODO: Clear game state cache data for previous tick to save memory GameState currGameState = Game.Current.CurrentTurn.GameState; GameSituation gameSituation = new GameSituation(currGameState); gameSituation.UpdateSituation(); // GameSituationsByTick[currGameState.Tick] = gameSituation; try { if (SolverState != SolverState.StoppingChoosingMoves) { EvaluateScenarioOfApplyingLockDownActions(currGameState, gameSituation); moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); } if (SolverState != SolverState.StoppingChoosingMoves) { EvaluateDodgeBulletScenario(currGameState, gameSituation); moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); } if (SolverState != SolverState.StoppingChoosingMoves) { EvaluateScenarioOfAttackingEnemyBase(currGameState, gameSituation); moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); } if (SolverState != SolverState.StoppingChoosingMoves) { EvaluateScenarioOfAttackingAnEnemyTank(currGameState, gameSituation); moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); } if (SolverState != SolverState.StoppingChoosingMoves) { EvaluateScenarioToAttackLockedDownEnemyTank(currGameState, gameSituation); moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); } if (SolverState != SolverState.StoppingChoosingMoves) { EvaluateScenarioOfAttackingAnUnarmedTank(currGameState, gameSituation); moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); } // Maxi-min scenarios... if (SolverState != SolverState.StoppingChoosingMoves) { EvaluateRunAtBaseScenario(currGameState, gameSituation); moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); } if (!gameSituation.AreAllTankActionsGenerated(YourPlayerIndex)) { EvaluateLockDownScenario(currGameState, gameSituation); moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); } } finally { // Always avoid hug me scenarios: EvaluateScenarioOfFriendlyTanksBlockingEachOther(currGameState, gameSituation); moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); } moveSet = TrySetBestMoveSoFar(currGameState, gameSituation); return; } catch { // Shortest Path Bot code: if (!moveSet) { ChooseShortestPathBotMoves(); } } }
private void EvaluateScenarioToAttackLockedDownEnemyTank(GameState currGameState, GameSituation gameSituation) { Scenario attackLockedDownEnemyTankScenario = new ScenarioToAttackLockedDownEnemyTank(currGameState, gameSituation, YourPlayerIndex); ScenarioEvaluator.EvaluateScenarioAndChooseMoves(attackLockedDownEnemyTankScenario, YourPlayerIndex); }
private void EvaluateLockDownScenario(GameState currGameState, GameSituation gameSituation) { Scenario lockDownScenario = new LockDownEnemyTankForOtherTankToDestroyScenario(currGameState, gameSituation); ScenarioEvaluator.EvaluateScenarioAndChooseMoves(lockDownScenario, YourPlayerIndex); }
private void EvaluateRunAtBaseScenario(GameState currGameState, GameSituation gameSituation) { Scenario runAtBaseScenario = new ClearRunAtBaseScenario(currGameState, gameSituation); ScenarioEvaluator.EvaluateScenarioAndChooseMoves(runAtBaseScenario, YourPlayerIndex); }
private void EvaluateScenarioOfDodgingBullets(GameState currGameState, GameSituation gameSituation) { Scenario scenario = new ScenarioToDodgeABullet(currGameState, gameSituation, YourPlayerIndex); ScenarioEvaluator.EvaluateScenarioAndChooseMoves(scenario, YourPlayerIndex); }
public RockPaperScissorsLizardSpock(string you, string opponent, GameSituation situation) : base(you, opponent, situation) { }
private void EvaluateScenarioOfApplyingLockDownActions(GameState currGameState, GameSituation gameSituation) { Scenario scenario = new ScenarioToApplyLockDownActions(currGameState, gameSituation); ScenarioEvaluator.EvaluateScenario(scenario); /* NB: There is no need to choose moves as well. * This will already be done while evaluating the scenario, * since there aren't alternative strategies to choose from, * so no MinMax is needed. */ }
public ConnectFour(string you, string opponent, GameSituation situation) : base(you, opponent, situation) { }
public void EnterZoneMode() { UnselectAllUnits (); ZonesParentGO.SetActive (true); Situation = GameSituation.Zone; }
private void EvaluateScenarioOfAttackingAnEnemyTank(GameState currGameState, GameSituation gameSituation) { Scenario scenario = new ScenarioOfAttackingAnEnemyTank(currGameState, gameSituation, YourPlayerIndex); ScenarioEvaluator.EvaluateScenario(scenario); }
public BaseGame(string you, string opponent, GameSituation situation) { You = you; Opponent = opponent; Situation = situation; }