Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from computer_functions import get_computer_move, HEAPS
- nop = int(input("Please enter the number of human players (1 or 2):")) #number of players
- if nop%2:
- namea = input("Please enter your name:")
- else:
- namea = input("Name of first player:")
- nameb = input("Name of second player:")
- player = True #True indicates its the turn of player number 1
- active = True #True while the board is not empty
- while active:
- print(sum)
- for i in range(len(HEAPS)):
- print(i+1, end = "")
- print(":")
- for K in range(HEAPS[i]):
- print("*", end="")
- print()
- if player:
- print(namea, "it's your turn:")
- elif not nop%2:
- print(nameb, "it's your turn:")
- while not nop%2 or player: #User move input
- move = [int(input("Row?"))]
- move[0] -= 1
- if not move[0] in range(len(HEAPS)):
- continue
- if HEAPS[move[0]] == 0:
- print("That row is empty")
- continue
- break
- move.append(int(0))
- while not nop%2 or player:
- move[1] = (int(input("How many?")))
- if move[1] <= HEAPS[move[0]] and move[1]:
- break
- if nop%2 and not player:
- move = list(get_computer_move(list(HEAPS)))
- print("Computer takes ", move[1], "from row ", move[0]+1)
- HEAPS = list(HEAPS)
- HEAPS[move[0]] = HEAPS[move[0]] - move[1]
- HEAPS = tuple(HEAPS)
- sum = 0
- for i in range(len(HEAPS)):
- sum += HEAPS[i]
- print(sum)
- if sum == 0:
- active = False
- player = not player #Gives the move to the next player
- if nop%2:
- if not player:
- print("You win")
- else:
- print("Computer wins")
- else:
- if not player:
- print(namea, "wins")
- else:
- print(nameb, "wins")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement