Exemplo n.º 1
0
        public override IPDGame.Choices Choice(IPDGame game)
        {
            lock (_choiceLock)
            {
                IPDGame.Choices pr;
                int             prt = game.T - 1;

                if (_initialChoices.Count > 0)
                {
                    return(_initialChoices.Dequeue());
                }
                else
                {
                    pr = game.GetChoice(this, prt);

                    if (pr == IPDGame.Choices.C)
                    {
                        _totalCooperateScore += (int)game.GetPast(this, prt);
                    }
                    else
                    {
                        _totalDefectScore += (int)game.GetPast(this, prt);
                    }

                    if (_initialChoices.Count > 0)
                    {
                        return(_initialChoices.Dequeue());
                    }
                    else
                    {
                        return((_totalDefectScore > _totalCooperateScore) ? IPDGame.Choices.D : IPDGame.Choices.C);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override IPDGame.Choices Choice(IPDGame game)
        {
            if (game.T == 0)
            {
                return(FIRST_CHOICE);
            }

            int i = 0;

            for (int k = 1; k <= _phenome.InputSignalArray.Length / 2; k++)
            {
                IPDGame.Past p = game.GetPast(this, game.T - k);
                //My choice (0 == C, 1 == D)
                _phenome.InputSignalArray[i++] = (p == IPDGame.Past.R || p == IPDGame.Past.S) ? 0 : 1;
                //Opponent choice
                _phenome.InputSignalArray[i++] = (p == IPDGame.Past.T || p == IPDGame.Past.R) ? 0 : 1;
            }

            _phenome.Activate();
            if (!_phenome.IsStateValid)
            {   // Any black box that gets itself into an invalid state is unlikely to be
                // any good, so lets just bail out here.
                return(IPDGame.Choices.R);
            }

            return((_phenome.OutputSignalArray[0] > _phenome.OutputSignalArray[1]) ? IPDGame.Choices.C : IPDGame.Choices.D);
        }
Exemplo n.º 3
0
        public override IPDGame.Choices Choice(IPDGame game)
        {
            lock (_choiceLock)
            {
                if (game.T == 0)
                {
                    game.HasRandom = _hasRandom;
                    return(_start);
                }

                switch (game.GetPast(this, game.T - 1))
                {
                case IPDGame.Past.T:
                    return(CooperateProbability(_t));

                case IPDGame.Past.R:
                    return(CooperateProbability(_r));

                case IPDGame.Past.P:
                    return(CooperateProbability(_p));

                case IPDGame.Past.S:
                    return(CooperateProbability(_s));
                }

                throw new Exception("How did we get here?");
            }
        }
Exemplo n.º 4
0
 public override int Evaluate(ref DecisionTree.Iterator iterator, IPDGame game)
 {
     if (_cond.Evaluate(iterator.Alpha, iterator.Beta))
     {
         iterator.Alpha += _alphaAdd;
         return(_left);
     }
     else
     {
         iterator.Beta += _betaAdd;
         return(_right);
     }
 }
Exemplo n.º 5
0
        public override IPDGame.Choices Choice(IPDGame game)
        {
            if (game.T == 0)
            {
                game.HasRandom = _hasRandom;
            }

            if (_iter >= _pattern.Length)
            {
                _iter = 0;
            }

            return(_pattern[_iter++]);
        }
Exemplo n.º 6
0
        public override IPDGame.Choices Choice(IPDGame game)
        {
            lock (_choiceLock)
            {
                if (_initialChoices.Count > 0)
                {
                    return(_initialChoices.Dequeue());
                }
                else
                {
                    if (C_D_TFT == -1)
                    {
                        switch (_alternative)
                        {
                        case Probes.One:
                        default:
                            C_D_TFT = (C(game, 1) && C(game, 2)) ? 1 : 2; break;

                        case Probes.Two:
                            C_D_TFT = (!C(game, 1) && C(game, 2)) ? 0 : 2; break;

                        case Probes.Three:
                            C_D_TFT = (C(game, 1)) ? 1 : 2; break;

                        case Probes.Hard:
                            C_D_TFT = (C(game, 1) && C(game, 2)) ? 1 : 2; break;
                        }
                    }

                    if (C_D_TFT == 0)
                    {
                        return(IPDGame.Choices.C);
                    }
                    else if (C_D_TFT == 1)
                    {
                        return(IPDGame.Choices.D);
                    }
                    else
                    {
                        return(C(game, game.T - 1) ? IPDGame.Choices.C : IPDGame.Choices.D);
                    }
                }
            }
        }
Exemplo n.º 7
0
 public override IPDGame.Choices Choice(IPDGame game)
 {
     lock (_choiceLock)
     {
         if (game.T == 0)
         {
             FillQueue(_initQ);
         }
         if (_q.Count == 0)
         {
             FillQueue(_tree.Run(game));
         }
         if (_q.Count == 0)
         {
             throw new Exception("Q is still empty?");
         }
         return(_q.Dequeue());
     }
 }
Exemplo n.º 8
0
        public override int Evaluate(ref DecisionTree.Iterator iterator, IPDGame game)
        {
            int t = game.T - _k - iterator.K;

            if (t < 0)
            {
                return(DecisionTree.INVOKE_Q);
            }

            if (_x.Contains(game.GetPast(iterator.Player, t)))
            {
                iterator.Alpha += _alphaAdd;
                return(_left);
            }
            else
            {
                iterator.Beta += _betaAdd;
                return(_right);
            }
        }
Exemplo n.º 9
0
        public override IPDGame.Choices Choice(IPDGame game)
        {
            lock (_choiceLock)
            {
                if (_initialChoices.Count > 0)
                {
                    return(_initialChoices.Dequeue());
                }
                else
                {
                    if (game.GetPast(this, game.T - 1) == IPDGame.Past.S || game.GetPast(this, game.T - 1) == IPDGame.Past.P)
                    {
                        _totalPSScore++;
                    }
                    else
                    {
                        _totalTRScore++;
                    }

                    return((_totalPSScore >= _totalTRScore) ? IPDGame.Choices.D : IPDGame.Choices.C);
                }
            }
        }
Exemplo n.º 10
0
        public IPDGame.Choices[] Run(IPDGame game)
        {
            int node = 0;

            IPDGame.Choices[] result = null;
            while (_tree.ContainsKey(node))
            {
                //Encountered a Assign Result node
                if (_tree[node].HasResult)
                {
                    result = _tree[node].Result.Evaluate(_iterator.Alpha, _iterator.Beta);
                    break;
                }

                node = _tree[node].Evaluate(ref _iterator, game);    //Alpha, Beta are not changed if INVOKE_Q

                //k - K < 0
                if (node == INVOKE_Q)
                {
                    result = _q.Evaluate(_iterator.Alpha, _iterator.Beta);
                    break;
                }
            }

            if (result == null)
            {
                throw new System.Exception("Result returned a null value");
            }
            else if (result.Length == 0)
            {
                throw new System.Exception("Result returned an empty value");
            }
            else
            {
                return(result);
            }
        }
Exemplo n.º 11
0
 public virtual int Evaluate(ref DecisionTree.Iterator iterator, IPDGame game)
 {
     throw new Exception("This node has not implemented an Evaluate function.");
 }
Exemplo n.º 12
0
 public override int Evaluate(ref DecisionTree.Iterator iterator, IPDGame game)
 {
     iterator.K++;
     return(_jumpTo);
 }
Exemplo n.º 13
0
 private bool C(IPDGame game, int time)
 {
     return(game.GetPast(this, time) == IPDGame.Past.R || game.GetPast(this, time) == IPDGame.Past.T);
 }