Ejemplo n.º 1
0
        public State GetNextState(State currentState, JointAction action)
        {
            var possibleStates = _transitionTable[new ProbabilityTransitionKey(currentState, action)];

            return(possibleStates[_random.Next(possibleStates.Count)]);
        }
Ejemplo n.º 2
0
        private void AddNextStateProbabilities(State currentState, JointAction action)
        {
            var possibleNextStates = new List <State>();

            var nextPlayerAPosition = GetNextPosition(currentState.PlayerAPosition, action.CurrentPlayerAction);
            var nextPlayerBPosition = GetNextPosition(currentState.PlayerBPosition, action.OpposingPlayerAction);

            //"When a player executes an action that would take it to the square occupied by the other player, possession of
            // the ball goes to the stationary player and the move does not take place"

            // Player A goes first and runs into player B's current position
            // or Player B goes first and runs into player A's position
            // "If the sequences of actions causes the players to collide, then only the first moves"
            if (nextPlayerAPosition == currentState.PlayerBPosition && nextPlayerBPosition == currentState.PlayerAPosition)
            {
                //50% chance that the player with the ball moves first in this scenario, and nobody moves.  As such, 50% chance the possession is changed to the other player.
                possibleNextStates.Add(new State(currentState.PlayerAPosition, currentState.PlayerBPosition, BallPossessor.A));
                possibleNextStates.Add(new State(currentState.PlayerAPosition, currentState.PlayerBPosition, BallPossessor.B));
            }
            //The second move will result in a collision.  Only the first move takes place and ball changes possession only if the second player possesses the ball
            else if (nextPlayerAPosition == nextPlayerBPosition)
            {
                possibleNextStates.Add(new State(currentState.PlayerAPosition, nextPlayerBPosition, BallPossessor.B));
                possibleNextStates.Add(new State(nextPlayerAPosition, currentState.PlayerBPosition, BallPossessor.A));
            }
            else if (nextPlayerAPosition == currentState.PlayerBPosition && nextPlayerBPosition != currentState.PlayerAPosition)
            {
                if (currentState.Possessor == BallPossessor.A)
                {
                    possibleNextStates.Add(new State(currentState.PlayerAPosition, currentState.PlayerBPosition, BallPossessor.B));
                }
                else
                {
                    possibleNextStates.Add(new State(currentState.PlayerAPosition, currentState.PlayerBPosition, BallPossessor.A));
                }

                possibleNextStates.Add(new State(nextPlayerAPosition, nextPlayerBPosition, currentState.Possessor));
            }
            else if (nextPlayerAPosition != currentState.PlayerBPosition && nextPlayerBPosition == currentState.PlayerAPosition)
            {
                if (currentState.Possessor == BallPossessor.B)
                {
                    possibleNextStates.Add(new State(currentState.PlayerAPosition, currentState.PlayerBPosition, BallPossessor.A));
                }
                else
                {
                    possibleNextStates.Add(new State(currentState.PlayerAPosition, currentState.PlayerBPosition, BallPossessor.B));
                }

                possibleNextStates.Add(new State(nextPlayerAPosition, nextPlayerBPosition, currentState.Possessor));
            }
            //No collision took place, deterministically move the players to their next locations
            else
            {
                possibleNextStates.Add(new State(nextPlayerAPosition, nextPlayerBPosition, currentState.Possessor));
            }

            possibleNextStates.RemoveAll(s => s.PlayerAPosition == s.PlayerBPosition);

            _transitionTable[new ProbabilityTransitionKey(currentState, action)] = possibleNextStates;
        }
Ejemplo n.º 3
0
 public ProbabilityTransitionKey(State currentState, JointAction action)
 {
     CurrentState = currentState;
     Action       = action;
 }