Re: the best way to make random events happen in my python game?

I have been considering this dilemma for quite a while now. I love AIs, I think they are really interesting, but, as you have just found out, building one is quite a task.
If I'm not mistaken, you are trying to create a version of a game called Pig. The catch here is your stopping point. Consider the following code:

import random
def computer_turn():
 should_stop = 0 #0 means continue rolling the dice
 while should_stop == 0:
  #This is just an example, you will want to change the print statement to either add the amount of points or check if the random number is equal to one, which signifies that the AI turn is complete
  print(random.randint(1, 6))
  #Update the should_stop variable and see if we should stop rolling the dice
  should_stop = random.randint(0, 1) #Remember, we only have a 50% chance to continue rolling

And there you have it. You will obviously want to modify the function to suit your needs, but I'll leave it up to you.
My issue with this approach is this:
This AI is incredibly simple. That's fine for a beginner project, but what if you want to improve this? How does the AI know to stop when it has a good score? When does it have a good score (The number varies player to player)? Should it play it safe, or should it be reckless and try to win as fast as possible?
One approach for doing it is to have different settings, but that still lacks the ability to change one's tactics based on the state of the game, i.e, I could decide to be more bold if I know that you are close to 100 points (The score at which a winner is declared), or I could decide to play it safe when I am close to 100 and you're only in your twenties.
Are there resources, articles, modules you all recommend to read / look up? I understand that there is only so much an AI can do in terms of simulating a real human player, but there must be a way to do this besides writing out a bunch of if statements, right?



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : SkyGuardian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : kianoosh via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : omer via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : philip_bennefall via Audiogames-reflector

Reply via email to