private Player SpawnPlayer(int playerNumber, int index, MoveSequence moves) { var playerObject = Instantiate( PlayerPrefab, this.Paths[index].PlayerTransform.position, this.Paths[index].PlayerTransform.rotation); Player player = playerObject.GetComponent <Player>(); if (playerObject.transform.position.x < this.gameObject.transform.position.x) { player.IsFlipped = true; } player.PlayerNumber = playerNumber; player.Attack.PlayerInput = new PlayerInput(playerNumber); PlayerDeathObserver observer = new PlayerDeathObserver(); observer.UpdateAction = this.OnPlayerDeath; player.AddPlayerDeathObserver(observer); if (RunTestFight) { player.Attack.AddMoveObserver(_moveRecorder.MovePerformedObserver); } var attackSpawnerObject = Instantiate( AttackSpawnerPrefab, this.Paths[index].AttakSpawnerTransform.position, this.Paths[index].AttakSpawnerTransform.rotation); var attackSpawner = attackSpawnerObject.GetComponent <BossAttackSpawner>(); attackSpawner.Target = player; attackSpawner.AttackPath = this.Paths[index]; attackSpawner.MovesData = moves; attackSpawner.SpawnDelay = this.SpawnDelay; attackSpawner.SpawningStartTime = this._fightStartTime; return(player); }
public Prediction MakePrediction(MoveSequence moveSequence) { string sequence = SequenceSelector(moveSequence); int rounds = sequence.Length; // TODO: Update matrix before making prediction if (rounds > Order) { char yourMove = moveSequence.YourMove(rounds - 1); char myMove = moveSequence.MyMove(rounds - 1); string lastSegment = sequence.Substring(rounds - Order - 1, Order); MyMatrix[lastSegment][myMove]++; YourMatrix[lastSegment][yourMove]++; } // Make next prediction if (rounds < Order) { return(new Prediction(ChooseWeighted(Initial), ChooseWeighted(Initial))); } string segment = sequence.Substring(rounds - Order, Order); if (!MyMatrix.ContainsKey(segment)) { MyMatrix[segment] = new Dictionary <char, double>(Initial); YourMatrix[segment] = new Dictionary <char, double>(Initial); } return(new Prediction(ChooseWeighted(MyMatrix[segment]), ChooseWeighted(YourMatrix[segment]))); }
/// <summary> /// Finds all the possible move sequences for the current player in a given match. /// </summary> /// <param name="match">Match to check against</param> /// <returns>A list of the possible move sequences</returns> public static List <MoveSequence> GenerateAllSequences(Match match) { List <Move> validMoves = GameLogic.GetValidMoves(match); List <MoveSequence> allSequences = new List <MoveSequence>(); foreach (Move possibleMove in validMoves) { Match dummyMatch = match.Clone(); switch (dummyMatch.board.ApplyMove(possibleMove)) { case MoveType.Jump: case MoveType.Capture: List <MoveSequence> possibleSequences = new List <MoveSequence>(); ExpandMoveSequences(new MoveSequence(), possibleMove, match.Clone(), possibleSequences); allSequences.AddRange(possibleSequences); break; case MoveType.Normal: MoveSequence basic = new MoveSequence(); basic.AddMove(possibleMove); allSequences.Add(basic); break; } } return(allSequences); }
public override MoveSequence QueryMovable(MoveType type) { const int MoveCount = 7; GridIndex[] sepIndex = new GridIndex[8] { new GridIndex(-1, 1), new GridIndex(1, 1), new GridIndex(1, -1), new GridIndex(-1, -1), new GridIndex(0, 1), new GridIndex(1, 0), new GridIndex(0, -1), new GridIndex(-1, 0) }; var seq = new MoveSequence(this, CellIndex, sepIndex.Length); for (int i = 1; i <= MoveCount; ++i) { for (int j = 0; j < sepIndex.Length; ++j) { seq.AddMove(j, sepIndex[j] * i); } } return(seq); }
/// <summary> /// Sequentially plays an AI move. /// </summary> /// <param name="moveSequence">The move sequence to be played</param> /// <remarks> /// The delay between each frame is the same as defined in PlayerPrefs('moveTime'). /// If unset, the default move time is applied. /// DefaultMoveTime is definied in <see cref="Constants"/>. /// </remarks> public IEnumerator PlayMoveSequence(MoveSequence moveSequence) { foreach (Move move in moveSequence.moves) { HighlightCells(new List <Position> { move.endPosition }); yield return(new WaitForSeconds(PlayerPrefs.GetFloat("moveTime", 1))); match.ExecuteMove(move); PlayGameAudioIfEnabled(pieceMovementSound); DrawCurrentState(); if (match.isOver) { PlayGameAudioIfEnabled(winSound); tip.text = match.currentFeedback; DisableBoardButtons(); yield break; // Exists the coroutine; since the game is over, no more moves should be drawn. } } if (match.unplacedPieces > 0) { Position[] aISpawnPositions = aI?.SpawnPieces(); StartCoroutine(PlayPieceSpawning(aISpawnPositions)); } }
public override void Update() { base.Update(); //Perform sequence MoveSequence.Update(); }
/// <summary> /// Gets the AI move sequence for the current state and plays it in a separate thread. /// </summary> public IEnumerator TriggerAi() { yield return(null); MoveSequence aIMoveSequence = aI?.Play(); tip.text = ""; StartCoroutine(PlayMoveSequence(aIMoveSequence)); }
public void AddMoveSequence(int playerNumber, MoveSequence moveSequence) { if (_currentIndex < MoveSequences.Length) { this.MoveSequences[this._currentIndex] = moveSequence; this.PlayerNumbers[this._currentIndex] = playerNumber; this._currentIndex++; } }
private void MoveBySequence(MoveSequence Sequence, int Speed, double Distance, ref Point LastPosition) { switch (Sequence) { // move along the logical X axis case MoveSequence.Right: if (this.Args.Axis.PhysicalAxisInst.Move(MoveMode.REL, Speed, Distance)) { LastPosition.X += Distance; } else { throw new InvalidOperationException(this.Args.Axis.PhysicalAxisInst.LastError); } break; // move along the logical X axis case MoveSequence.Left: if (this.Args.Axis.PhysicalAxisInst.Move(MoveMode.REL, Speed, -Distance)) { LastPosition.X -= Distance; } else { throw new InvalidOperationException(this.Args.Axis.PhysicalAxisInst.LastError); } break; // move along the logical Y axis case MoveSequence.Up: if (this.Args.Axis2.PhysicalAxisInst.Move(MoveMode.REL, Speed, Distance)) { LastPosition.Y += Distance; } else { throw new InvalidOperationException(this.Args.Axis2.PhysicalAxisInst.LastError); } break; // move along the logical Y axis case MoveSequence.Down: if (this.Args.Axis2.PhysicalAxisInst.Move(MoveMode.REL, Speed, -Distance)) { LastPosition.Y -= Distance; } else { throw new InvalidOperationException(this.Args.Axis2.PhysicalAxisInst.LastError); } break; } }
public void _new(BaseCarDivice baseCarDivice) { GPSSpotManager = new GPSSpotManager(0); //GPSSpotManager.AddPos(new GPSsPosition(10, 10).GetGPSPosition()); carDivice = baseCarDivice; EnableTraceMode = true; CurrentMoveSequence = MoveSequence.ForcedForward; carDivice.statusparser.OnParsedSOP += Statusparser_OnParsedSOP; }
public MoveSequence Clone() { MoveSequence cloned = new MoveSequence(); foreach (Move move in moves) { cloned.moves.Add(move.Clone()); } return(cloned); }
public static Prediction PredictMoveFromIndex(int index, MoveSequence sequence) { if (index > -1) { return(new Prediction(sequence.MyMove(index), sequence.YourMove(index))); } else { return(new Prediction(RandomRPS(), RandomRPS())); } }
public MoveSequence QueryCastling(ChessBoard board, out bool bQueenSide, out bool bKingSide) { bQueenSide = false; bKingSide = false; if (!IsFirstAction) { return(new MoveSequence(this, CellIndex, 0)); } var queenSide = new GridIndex(CellIndex.X - 4, CellIndex.Y); var kingSide = new GridIndex(CellIndex.X + 3, CellIndex.Y); int available = 0; if (board[queenSide] is Rook rook1 && rook1.IsFirstAction) { if (CheckQueenSideLine(board)) { bQueenSide = true; available += 1; } } if (board[kingSide] is Rook rook2 && rook2.IsFirstAction) { if (CheckKingSideLine(board)) { bKingSide = true; available += 1; } } if (!bQueenSide && !bKingSide) { return(new MoveSequence(this, CellIndex, 0)); } int seqIdx = 0; var seq = new MoveSequence(this, CellIndex, available); if (bQueenSide) { seq.AddMove(seqIdx++, new GridIndex(-2, 0)); } if (bKingSide) { seq.AddMove(seqIdx++, new GridIndex(2, 0)); } return(seq); }
public void StartSequence(params BattleEntity[] targets) { MoveSequence.StartSequence(targets); //Catch a reference error early on if (HasActionCommand == true) { if (actionCommand.Handler != MoveSequence) { Debug.LogError($"The Action Command's Handler for {Name} is NOT the MoveSequence reference! This WILL cause problems, so fix ASAP"); Debug.LogError($"Type name for Handler: {actionCommand.Handler.GetType().Name} and for MoveSequence: {MoveSequence.GetType().Name}"); } } }
/// <summary> /// Plays a sequence of moves on the board. /// </summary> /// <param name="moveSequence">MoveSequence object containing all the moves to play</param> /// <remarks> /// This method does not verify if the moves in the sequence are valid, it just blindly applies them. /// </remarks> public void ApplyMoveSequence(MoveSequence moveSequence) { foreach (Move move in moveSequence.moves) { byte destinyValue = GetCellValue(move.startPosition); SetCellValue(move.startPosition, EmptyCell); SetCellValue(move.endPosition, destinyValue); Position midpoint = move.Midpoint(); // If midpoint exists, this is a special move if (midpoint != null && GetCellValue(midpoint) != destinyValue) // Capture { SetCellValue(midpoint, EmptyCell); } } }
public override MoveSequence QueryMovable(MoveType type) { var seq = new MoveSequence(this, CellIndex, 8); seq.AddMove(0, new GridIndex(-2, 1)); seq.AddMove(1, new GridIndex(-1, 2)); seq.AddMove(2, new GridIndex(1, 2)); seq.AddMove(3, new GridIndex(2, 1)); seq.AddMove(4, new GridIndex(2, -1)); seq.AddMove(5, new GridIndex(1, -2)); seq.AddMove(6, new GridIndex(-1, -2)); seq.AddMove(7, new GridIndex(-2, -1)); return(seq); }
public void GetMoves_SingleJumpAndMakeKingSequence() { var board = new SquareBoard(3); board.Set(Figure.CreateSimple(2, 2, Side.Black)); board.Set(Figure.CreateSimple(1, 1, Side.Red)); testOutput.WriteLine(board.ToString()); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var move = moves[Figure.CreateSimple(2, 2, Side.Black)].Single(); var expectedSequence = new MoveSequence(MoveStep.Jump(0, 0), MoveStep.King()); Assert.Equal(expectedSequence, move); }
public override void Draw() { base.Draw(); if (MoveSequence.InSequence == true) { //Don't show Action Command information if we shouldn't if (CommandEnabled == true && DrawActionCommandInfo == true) { SpriteRenderer.Instance.DrawUIText(AssetManager.Instance.TTYDFont, $"Command: {Name} performed by {User.Name}", new Vector2(RenderingGlobals.BaseResolutionWidth / 2, 50f), Color.Black, 0f, new Vector2(.5f, .5f), 1.1f, .9f); } MoveSequence.Draw(); } }
public void GetMoves_PresetBoard_KingCanJumpBack() { var board = Board6x6Preset1(); testOutput.WriteLine(board.ToString()); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var kingMoves = moves[Figure.CreateKing(2, 0, Side.Black)]; var expectedKingSequence = new MoveSequence( MoveStep.Jump(0, 2), MoveStep.Jump(2, 4), MoveStep.Jump(0, 6)); Assert.Equal(expectedKingSequence, kingMoves.Single()); }
public void GetMoves_PresetBoard_SimpleShouldStopWhenPromoted() { var board = Board6x6Preset1(); testOutput.WriteLine(board.ToString()); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var simpleMoves = moves[Figure.CreateSimple(4, 6, Side.Black)]; var jumpUntilPromotedToKing = new MoveSequence( MoveStep.Jump(2, 4), MoveStep.Jump(0, 2), MoveStep.King()); Assert.Contains(jumpUntilPromotedToKing, simpleMoves); }
void Start() { _fightStartTime = AudioSettings.dspTime + MusicDelay; var musicManagerObject = Instantiate(MusicManagerPrefab); var musicManager = musicManagerObject.GetComponent <MusicManager>(); musicManager.Tune.clip = this.Tune; musicManager.PlayMusicStartTime = _fightStartTime; this.BossAnimation.MoveStartTime = _fightStartTime; if (RunTestFight) { _moveRecorder = this.gameObject.AddComponent <MoveRecorder>(); _moveRecorder.RecordingStartTime = _fightStartTime; _moveRecorder.MoveSpeed = this.TestFightAttackSpeed; if (MoveHistoryDestination != null) { _moveRecorder.SaveFilePath = MoveHistoryDestination; } MoveSequence movesData = new MoveSequence(); movesData.Speed = this.TestFightAttackSpeed; movesData.MovesInTime = new MoveData[] { new MoveData(MoveType.Forward, 0) }; for (int i = 0; i < GameSettings.PlayerNumber; i++) { Player newPlayer = SpawnPlayer(i + 1, i, movesData); this._players.Add(newPlayer); } } else { var recordReader = new RecordReader(this.DataPath); FightData fightData = recordReader.MovesData; this.BossAnimation.AnimationSpeed = fightData.BossAnimationSpeed; for (int i = 1; i <= GameSettings.PlayerNumber; i++) { Player newPlayer = SpawnPlayer(i, i - 1, fightData.GetMovesForPlayerNumber(i)); this._players.Add(newPlayer); } } }
public void GetMoves_SingleSimple_PromoteToKing() { var figure = Figure.CreateSimple(1, 1, Side.Black); var board = new SquareBoard(3); board.Set(figure); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var figureMoves = Assert.Contains(figure, moves); var expectedTopLeft = new MoveSequence(MoveStep.Move(0, 0), MoveStep.King()); var expectedBottomRight = new MoveSequence(MoveStep.Move(0, 2), MoveStep.King()); Assert.Contains(expectedTopLeft, figureMoves); Assert.Contains(expectedBottomRight, figureMoves); Assert.Equal(2, figureMoves.Length); }
public override void Draw() { base.Draw(); if (MoveSequence.InSequence == true) { if (CommandEnabled == true) { SpriteRenderer.Instance.DrawText(AssetManager.Instance.TTYDFont, $"Command: {Name} performed by {User.Name}", new Vector2(SpriteRenderer.Instance.WindowCenter.X, 50f), Color.Black, 0f, new Vector2(.5f, .5f), 1.1f, .9f, true); actionCommand?.Draw(); } MoveSequence.Draw(); } }
public void GetMoves_SingleSimple_ForwardOnly() { /* . . . . * . . . . * . b . . * . . . . */ var board = new SquareBoard(4); board.Set(Figure.CreateSimple(2, 1, Side.Black)); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var figureMoves = moves.Single().Value; var expectedTopLeft = new MoveSequence(MoveStep.Move(1, 0)); var expectedTopRight = new MoveSequence(MoveStep.Move(1, 2)); Assert.Contains(expectedTopLeft, figureMoves); Assert.Contains(expectedTopRight, figureMoves); Assert.Equal(2, figureMoves.Length); }
/// <summary> /// Expands a move to form every possible capture or jump sequence from it. /// </summary> /// <param name="expandingSequence">Move sequence being expanded</param> /// <param name="move">Move to expand from</param> /// <param name="match">Match to check against</param> /// <param name="moveSeqList">List of the expanded move sequences</param> /// <remarks> /// The <paramref name="moveSeqList"/> should be initialized as a new object before the initial function call. /// </remarks> private static void ExpandMoveSequences(MoveSequence expandingSequence, Move move, Match match, List <MoveSequence> moveSeqList) { expandingSequence.AddMove(move); match.ExecuteMove(move); List <Position> nextDestinies = move.type == MoveType.Capture? GameLogic.GetCaptureMoveDestinies(match, move.endPosition) : GameLogic.GetJumpMoveDestinies(match, move.endPosition); if (nextDestinies.Count == 0) { moveSeqList.Add(expandingSequence); return; } List <Move> nextMoves = ToMovesList(move.endPosition, nextDestinies, move.type == MoveType.Capture? MoveType.Capture : MoveType.Jump); foreach (Move nextMove in nextMoves) { Match dummyMatch = match.Clone(); dummyMatch.ExecuteMove(nextMove); MoveSequence moveSeqTemp = expandingSequence.Clone(); ExpandMoveSequences(moveSeqTemp, nextMove, match.Clone(), moveSeqList); } }
public MoveSequence QueryEnpassant(ChessBoard board) { var seq = new MoveSequence(this, new GridIndex(0, 0), 2); GridIndex dir; switch (Team) { case ChessTeam.Black: dir = ChessBoard.ToWhite; break; case ChessTeam.White: dir = ChessBoard.ToBlack; break; default: throw new InvalidOperationException(); } dir += CellIndex; var left = new GridIndex(-1, 0); var right = new GridIndex(1, 0); left += CellIndex; right += CellIndex; if (left.IsValid && board[left] is Pawn leftPawn && leftPawn.Team != Team && leftPawn.enpassantTarget != 0) { seq.AddMove(1, new GridIndex(left.X, dir.Y)); } if (right.IsValid && board[right] is Pawn rightPawn && rightPawn.Team != Team && rightPawn.enpassantTarget != 0) { seq.AddMove(1, new GridIndex(right.X, dir.Y)); } return(seq); }
public void StartClicked(object sender, EventArgs e) { if (!IsGood(Regexp.Text)) { Regexp.Foreground = Brushes.Red; Regexp.Text = "Illegal Expression"; return; } if (!started) { Start.IsEnabled = false; first = true; started = true; matched = true; moveSeq = new MoveSequence(Regexp.Text); Regexp.Foreground = Brushes.Blue; Regexp.IsReadOnly = true; //Regexp.Di } }
public void GetMoves_PresetBoard_SimpleHasSeveralJumpBranches() { var board = Board6x6Preset1(); testOutput.WriteLine(board.ToString()); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var simpleMoves = moves[Figure.CreateSimple(4, 6, Side.Black)]; var expectedSimpleSequence1 = new MoveSequence( MoveStep.Jump(2, 4), MoveStep.Jump(0, 2), MoveStep.King()); var expectedSimpleSequence2 = new MoveSequence( MoveStep.Jump(2, 4), MoveStep.Jump(0, 6), MoveStep.King()); Assert.Collection(simpleMoves, (x) => Assert.Equal(expectedSimpleSequence1, x), (x) => Assert.Equal(expectedSimpleSequence2, x)); }
public void GetMoves_SingleKing_AllEmptySides() { /* . . . . * . . b . * . β . . * b . . . */ var board = new SquareBoard(4); var king = Figure.CreateKing(2, 1, Side.Black); board.Set(king); board.Set(Figure.CreateSimple(3, 0, Side.Black)); board.Set(Figure.CreateSimple(1, 2, Side.Black)); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var figureMoves = moves[king]; var expectedTopLeft = new MoveSequence(MoveStep.Move(1, 0)); var expectedBottomRight = new MoveSequence(MoveStep.Move(3, 2)); Assert.Contains(expectedTopLeft, figureMoves); Assert.Contains(expectedBottomRight, figureMoves); Assert.Equal(2, figureMoves.Length); }
public void AddVariation(int ID, MoveSequence variation) { Variations[ID] = new MoveSequence(variation); }
internal GameStateGameOver(MoveSequence moveSequence) : base(moveSequence) { }
protected internal GameStateBase(MoveSequence moveSequence) { MoveSequence = moveSequence; }