AIXI.MyTttEnvironment.PerformAction C# (CSharp) Method

PerformAction() public method

public PerformAction ( int action ) : int>.Tuple
action int
return int>.Tuple
        public override Tuple<int, int> PerformAction(int action)
        {
            Debug.Assert(this.IsValidAction(action));

            this.Action = action;

            this._actionsSinceReset+=1;
            int r = action / 3;
            int c = action % 3;

            if (this.Board[r, c] != this.OEmpty) {
                this.Reward = this.RInvalid;
                this.Reset();
                return new Tuple<int,int>(this.Observation, this.Reward);
            }

            this.Board[r, c] = this.OAgent;
            if (this.check_win()) {
                this.Reward = this.RWin;
                this.Reset();
                return new Tuple<int, int>(this.Observation, this.Reward);
            }
            else if (this._actionsSinceReset == 5) {
                this.Reward = this.RDraw;
                this.Reset();
                return new Tuple<int, int>(this.Observation, this.Reward);
            }

            while (this.Board[r, c] != this.OEmpty) {
                r = Utils.Rnd.Next(0, 3);
                c = Utils.Rnd.Next(0, 3);
            }

            this.Board[r, c] = this.OEnv;
            if (this.check_win()) {
                this.Reward = RLoss;
                this.Reset();
                return new Tuple<int, int>(this.Observation, this.Reward);
            }

            this.Reward = RNull;
            this.compute_observation();

            return new Tuple<int, int>(this.Observation, this.Reward);
        }