Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Putting a strategy into a python agent

So im working on some agents to play the Axelrods python game, the agent i currently have is below, what i would like to know is how would i implement a new strategy into this agent? A strategy such as one that always defects? The agent always needs to return either a 'C' for cooperate or D for defect.

Code
class PlayerFlipper:

    def move(self, history):
        mine, theirs = history
        if len(mine) % 2 == 0:
            return 'C'
        else:
            return 'D'
[/quote]
Well, if you want to always defect, just return 'D' every time.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
(Nov 23, 2016 09:40 AM)Goodies Wrote:  Well, if you want to always defect, just return 'D' every time.

Thanks for your reply, okay so how could i turn it into a strategy thats random, so the agent cooperates or defects on a completely random basis?

Another strategy that i want to implement is a Mimic strategy so it mimics other players moves based on previous rounds.
(Nov 23, 2016 10:36 AM)S M I T H Y Wrote:  Thanks for your reply, okay so how could i turn it into a strategy thats random, so the agent cooperates or defects on a completely random basis?

Another strategy that i want to implement is a Mimic strategy so it mimics other players moves based on previous rounds.

how about:

PHP Code

<?php 
import random
...
#in your function:
return random.choice(("D", "C")) 
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
(Nov 23, 2016 10:36 AM)S M I T H Y Wrote:  Thanks for your reply, okay so how could i turn it into a strategy thats random, so the agent cooperates or defects on a completely random basis?

Another strategy that i want to implement is a Mimic strategy so it mimics other players moves based on previous rounds.

You can use the random library.

PHP Code

<?php 
import random
random 
= random.randint(1,4) #range of numbers
if random == 1:
    print(
"your code") #your code if random is 4
elif random == 2:
    print 
"your code" 
else:
    print (
"error") # if random is 3 or 4 

Is this what you mean by a 'random' strategy?


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 630 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[Python] by ROU001May 5, 2021 03:11 PM 7 245 May 5, 2021 03:11 PM
Last Post: vegaoceansoda
[Python] by Ineed2learn2eatJul 13, 2017 10:48 AM 3 228 Jul 13, 2017 10:48 AM
Last Post: Ineed2learn2eat