views:

114

answers:

2

I have little to no formal discrete math training, and have run into a wee bit of an issue. I am trying to write an agent which reads in a human player's (arbitrary) score and scores a point every so often. The agent needs to "lag behind" and "catch up" every so often, so that the human player believes there is some competition going on. Then, the agent must either win or lose (depending on the condition) against the human.

I have tried a few different techniques, including a wonky probabilistic loop (which failed horribly). I was thinking that this problem calls for something like an emission Hidden Markov Model (HMM), but I'm not sure how to implement it (or even whether this is the best approach).

I have a gist up, but again, it sucks.

I hope the __main__ function provides some insight as to the goal of this agent. It is going to be called in pygame.

A: 

I am making the assumption that the human cannot see the computer agent playing the game.  If this is the case, here is one idea you might try.

Create a list of all the possible point combinations that can be scored for any given move.  For each move, find a score range which you would like the agent to end up within after the current turn.  Reduce the set of possible move values to only the values which would end the agent in that particular range and randomly select one.  As conditions change for how far behind or ahead you would like the agent to get, simply slide your range appropriately.

If you are looking for something with some kind of built in and researched psychological effects for the human, I cant help you with that.  You will need to define more rules for us if you want something more specific to your situation than this.

NickLarsen
I'm liking this. I'll try implementing it on Saturday.
Octaflop
+2  A: 

I think you may be over-thinking this. You can use simple probability to estimate how often and by how much the computer's score should "catch-up". Additionally, you can calculate the difference between the computer's score and human's score, and then feed this to a sigmoid-like function to give you the degree at which the computer's score increases.

Illustrative Python:

#!/usr/bin/python
import random, math
human_score = 0
computer_score = 0
trials = 100
computer_ahead_factor = 5 # maximum amount of points the computer can be ahead by
computer_catchup_prob = 0.33 # probability of computer catching up
computer_ahead_prob = 0.5 # probability of computer being ahead of human
computer_advantage_count = 0
for i in xrange(trials):
    # Simulate player score increase.
    human_score += random.randint(0,5) # add an arbitrary random amount
    # Simulate computer lagging behind human, by calculating the probability of
    # computer jumping ahead based on proximity to the human's score.
    score_diff = human_score - computer_score
    p = (math.atan(score_diff)/(math.pi/2.) + 1)/2.
    if random.random() < computer_ahead_prob:
        computer_score = human_score + random.randint(0,computer_ahead_factor)
    elif random.random() < computer_catchup_prob:
        computer_score += int(abs(score_diff)*p)
    # Display scores.
    print 'Human score:',human_score
    print 'Computer score:',computer_score
    computer_advantage_count += computer_score > human_score
print 'Effective computer advantage ratio: %.6f' % (computer_advantage_count/float(trials),)
Chris S