internal void TakeIfBetter(GameState nextScoredMove, int scoreIndex, IPlayerMove thisMove) { double otherOffsetScore = nextScoredMove[scoreIndex] - Scores[scoreIndex]; bool takeIt = false; if (Math.Abs(otherOffsetScore) < double.Epsilon) { if (nextScoredMove.Scores.Sum() < Scores.Sum()) { takeIt = true; } } else if (otherOffsetScore < 0.0) { return; // not take it } else if (otherOffsetScore > 0.0) { takeIt = true; } if (takeIt) { NextGameState = nextScoredMove; Scores = nextScoredMove.Scores; BestMove = thisMove; } }
//------------------------------------------ // 初期化 //------------------------------------------ #region ===== INITIALIZE ===== /// <summary> /// World 座標系で座標を扱うので注意!! /// </summary> /// <param name="_sys"></param> public void Initialize(InputSystem _sys, Camera _mainCam, IPlayerMove _playerMove) { m_mainCamera = _mainCam; m_playerMove = _playerMove; Sprite baseSprite = m_baseSpriteTrans.GetComponent <SpriteRenderer>().sprite; m_baseSpriteParam.PixelPerUnit = baseSprite.pixelsPerUnit; m_baseSpriteParam.Radius = baseSprite.bounds.size.x * 0.5f; Sprite childSprite = m_stickSpriteTrans.GetComponent <SpriteRenderer>().sprite; m_stickerSpriteParam.PixelPerUnit = childSprite.pixelsPerUnit; m_stickerSpriteParam.Radius = childSprite.bounds.size.x * 0.5f; // Base の可動域の設定 m_baseMoveRange_X.x = MainCam.ScreenToWorldPoint(new Vector3(0f, 0f, 0f)).x + BaseSpriteRadius; m_baseMoveRange_X.y = MainCam.ScreenToWorldPoint(new Vector3(Screen.width, 0f, 0f)).x - BaseSpriteRadius; m_baseMoveRange_Y.x = MainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height, 0f)).y - BaseSpriteRadius; m_baseMoveRange_Y.y = MainCam.ScreenToWorldPoint(new Vector3(0, 0f, 0f)).y + BaseSpriteRadius; // Stick の可動域 m_stickMoveRange = (BaseSpriteRadius - m_stickerSpriteParam.Radius);// Radius // _sys.AddOnDragStartEvent( this.OnDragStart ); // _sys.AddOnDragEvent( this.OnDrag ); // _sys.AddOnDragEndEvent( this.OnDragEnd ); HideUI(); }
private ScoredMove ScoreMove(IGame game, IPlayerMove move) { double score = 0; if (move is IBuildCampusMove) { var bMove = (IBuildCampusMove) move; score = bMove.CampusType == CampusType.Super ? 30 : 20; } else if (move is IBuildLinkMove) { score = 15; var bMove = (IBuildLinkMove) move; if (game.IBoard[bMove.WhereAt].Adjacent.Vertices.Any(vertex => vertex.IsFreeToBuildCampus())) { score += 1; } } else if (move is ITradingMove) { score = 10; } else if (move is ITryStartUpMove) { if (game.CurrentIUniversity.Students.Values.Sum() > 5) { score = 5; } else { score = -5; } } return new ScoredMove(move, score); }
static void PrintBoardAfterMove(IPlayerMove move, string playerName, SimpleBoard board) { var piece = board.Get(move.Move.StartPosition.ToTuple()); if (move.Move.PromotionResult != PromotionPieceType.NoPromotion) { if (piece.Contains("w")) { piece = "wQ "; } else { piece = "bQ "; } } // Clear previous move for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (board.Get((i, j)) == SimpleBoard.PreviousTileValue) { board.Set((i, j), " "); break; } } } board.Set(move.Move.StartPosition.ToTuple(), SimpleBoard.PreviousTileValue); board.Set(move.Move.EndPosition.ToTuple(), piece); board.Print(); }
public bool MoveAffectedByEncumberedStatus(IAdventurePlayer player, IPlayerMove move) { if (player.Statuses.Contains(PlayerStatus.IsEncumbered)) { player.ChatClient.PostDirectMessage(player, "You are currently encumbered."); if (move.Moves.Contains("up")) { player.ChatClient.PostDirectMessage(player, "You are unable to move upward!"); player.ChatClient.PostDirectMessage(player, "*" + player.CurrentLocation.Name + "*"); return(true); } if (move.Moves.Contains("down")) { player.ChatClient.PostDirectMessage(player, "You slip and fall! All that weight drags you down. " + "Your lamp smashes and darkness engulfs you..."); player.Statuses.Add(PlayerStatus.IsDead); _game.EndOfGame(player); return(true); } } return(false); }
public PlayerController(IPlayerMove playerMove, IPlayerGun playerGun) { move = playerMove; gun = playerGun; EventManager.Instance.AddListener <InputEvent>(HandleInput); EventManager.Instance.AddListener <GameOverEvent>(HandleGameOver); }
public void PrintIllegalMove(IPlayerMove move) { ColorConsole.WriteLine(ConsoleColor.Red, "Illegal Move '{0}' for university {1}", move, _game.CurrentUniversity); }
void Awake() { Utility.ChangeSprite(gameObject, GameConfig.playerImg); player = PlayerData.Instance(); // microphone = new MicrophoneInput (player); // if(GameConfig.mic) moveController = PlayerMoveLine.Instance (player); initMoveDic(player); moveController = movesDic["start"]; }
public static Move ToGrpc(IPlayerMove playerMove) { var grpcMove = new Move() { Diagnostics = playerMove.Diagnostics, Chess = ToGrpc(playerMove.Move) }; return(grpcMove); }
public async Task <IBoardState> ApplyValidatedMove(IPlayerMove playerMove) { var move = playerMove.ToEngineMove(); ChessGame.ApplyMove(move, true); State.Moves.Add(move); State.ETag = Guid.NewGuid().ToString(); await WriteStateAsync(); return(await GetBoardState()); }
public static Move ToEngineMove(this IPlayerMove playerMove) { switch (playerMove) { case PlayerIMove move: return(new Move(move.OriginalPosition, move.NewPosition, Player.White, move.Promotion)); case PlayerIIMove move: return(new Move(move.OriginalPosition, move.NewPosition, Player.Black, move.Promotion)); default: throw new System.Exception("Unknown player move"); } }
/// <inheritdoc/> public async Task <ITurnResult> Play(IPlayer player, IPlayerMove playedMove) { if (!await player.IsCurrentTurn) { return(TurnResult.Failed(player, "Its currently not your turn.")); } var gameSquare = GameSquares.SingleOrDefault(gameSquare => gameSquare.Rectangle.IsInRange(playedMove.NewPosition)); if (gameSquare == null) { return(TurnResult.Failed(player, "Invalid gameSquare")); } return(TurnResult.Success(player, gameSquare, "Acceptable move")); }
static void PrintMove(IPlayerMove move, string playerName) { var message = $"{playerName.PadRight(10)}- {move.Move.StartPosition} to "; //if (move.Move.Capture) info += "x"; message += $"{move.Move.EndPosition}"; if (move.Move.CheckMate) { message += "#"; } else if (move.Move.Check) { message += "+"; } message += ". "; //message += Environment.NewLine; message += $"{move.Diagnostics}"; Log(message); }
private GameState GetNextScores(IGame game, int depth, int playerIndex, IPlayerMove move) { depth -= 1; game.ApplyMove(move); GameState nextBestScoredMoves = null; if (_transTable != null) { nextBestScoredMoves = _transTable.GetBestScoredMoves(game.Hash, depth); } if (nextBestScoredMoves == null) { nextBestScoredMoves = SearchBestMoves(game, depth, playerIndex); if (_transTable != null) { _transTable.Remember(game.Hash, nextBestScoredMoves, depth); } } game.UndoMove(); return nextBestScoredMoves; }
public void AddPlayerMove(IPlayerMove playerMove) { playerMoves.Add(playerMove); logger($"Player {playerMove.GetPlayer().GetId()} moved from {playerMove.GetStartingPosition()} to {playerMove.GetEndingPosition()}"); }
internal void ConsumeStudents(IPlayerMove move) { if (move.StudentsNeeded == null) { return; } foreach (StudentGroup group in move.StudentsNeeded) { _game.Hashing.HashDegree(Color, group.Degree, Students[group.Degree]); Students[group.Degree] -= group.Quantity; _game.Hashing.HashDegree(Color, group.Degree, Students[group.Degree]); } }
public Task <bool> IsValidMove(IPlayerMove move) => Task.FromResult(ChessGame.IsValidMove(move.ToEngineMove()));
protected virtual void UpdateMove() { moveController.prepareNextMove(); moveController = movesDic[player.status]; }
public HandType() { this.randomGenerator = new Random(); this.playerMove = new PlayerMove(); }
public void ApplyMove(IPlayerMove move) { var updateMove = move as IPlayerMoveForUpdate; Debug.Assert(updateMove != null); _previousTurnInfo.Push(TurnInfo.Create(this, updateMove)); updateMove.ApplyTo(this); _allAvailableMoves = null; if (CurrentPhase == GamePhase.Play) { CurrentUniversity.ConsumeStudents(move); } if (CurrentPhase == GamePhase.Setup2 && move is BuildCampusMove) { CurrentUniversity.AcquireInitialStudents(((BuildCampusMove) move).WhereAt); } if (CurrentPhase != GamePhase.Play && !(move is EndTurn)) // setup phase { if (!_setupMoveGenerator.ShouldBuildCampus) { ApplyMove(new EndTurn()); } _setupMoveGenerator.Toggle(); } }
internal void ResumeStudents(IPlayerMove move) { if (move.StudentsNeeded == null) { return; } foreach (StudentGroup group in move.StudentsNeeded) { Students[group.Degree] += group.Quantity; } }
private void CheckAndApply(IPlayerMove move) { if (_game.IsLegalMove(move)) { _game.ApplyMove(move); } else { throw new Exception("Illegal move: " + move); } }
public bool IsLegalMove(IPlayerMove move) { if (move is RandomMove) { return true; } if (CurrentPhase == GamePhase.Play && !CurrentUniversity.HasStudentsFor(move.StudentsNeeded)) { return false; } var updateMove = move as IPlayerMoveForUpdate; Debug.Assert(updateMove != null); return updateMove.IsLegalToApply(this); }
public GameState(IPlayerMove move, double[] scores) { BestMove = move; Scores = scores; }
public HandType() { this.randomGenerator = new Random(); this.playerMove = new PlayerMove(); }
public ScoredMove(IPlayerMove move, double score) { Move = move; Score = score; }
public void ClearData() { _IPlayerAttack = null; _IPlayerMove = null; }
private ScoredMove ScoreMove(IGame game, IPlayerMove move) { var buildLinkMove = move as IBuildLinkMove; if (buildLinkMove != null) { return GetBuildLinkMoveScore(game, buildLinkMove); } var buildCampus = move as IBuildCampusMove; return buildCampus == null ? new ScoredMove(move, 100) : new ScoredMove(move, GetVertexScore(game, game.IBoard[buildCampus.WhereAt])); }
public void PrintLegalMove(IPlayerMove move) { ColorConsole.WriteLineIf(_game.HasHumanPlayer, ConsoleViewerColor.Move, move); }
public void SetData(IPlayerAttack playerAttack, IPlayerMove playerMove, int userId) { _IPlayerAttack = playerAttack; _IPlayerMove = playerMove; _UserId = userId; }