Python Forum
Assign 1 player to the computer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assign 1 player to the computer
#3
Your player = False and the accompanying logic at the start of your loop (lines 21-28) isn't really accomplishing anything at this point. In a game with only two players, you don't necessarily need to use a variable to keep track of whose turn it is. A simple way to handle having one human and one computer player is to include both turns in your main game loop. You get the player's move, apply it, check if the game is over, then do the same for the computer move. Break out when the game ends.

This pseudocode is not at all complete, but gives you the basic idea:

while True:
    print('Number of counters', state)

    human_move = int(input('Enter your move'))
    state = state - human_move
    if state == 1:
        print('Human wins')
        break

    print('Number of counters', state)

    computer_move = random.randint(1, 3)
    print('Computer move is', computer_move)
    state = state - computer_move
    if state == 1:
        print('Computer wins')
        break
Reply


Messages In This Thread
Assign 1 player to the computer - by ironic100 - Aug-14-2020, 10:22 AM
RE: Assign 1 player to the computer - by GOTO10 - Aug-14-2020, 01:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My code won't say Player wins or computer wins. No errors. its_a_meLuigi64 2 1,764 Dec-01-2021, 04:43 PM
Last Post: its_a_meLuigi64

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020