Code: Select all
init python: # Initializes Python code block
import random # Imports the random module for shuffling and making random choices
class Domino: # Defines a class named Domino to represent individual domino tiles
def __init__(self, value1, value2): # Constructor method to initialize Domino objects
self.value1 = value1 # Sets the first value of the domino
self.value2 = value2 # Sets the second value of the domino
def __str__(self): # Defines a method to return a string representation of the Domino object
return f"[{self.value1}|{self.value2}]" # Returns a string with the domino values enclosed in square brackets
# Creates a list of all possible dominoes (28 in total) using the Domino class constructor
dominoes = [Domino(0, 0), Domino(0, 1), Domino(0, 2), Domino(0, 3), Domino(0, 4), Domino(0, 5), Domino(0, 6), Domino(1, 1), Domino(1, 2), Domino(1, 3), Domino(1, 4), Domino(1, 5), Domino(1, 6), Domino(2, 2), Domino(2, 3), Domino(2, 4), Domino(2, 5), Domino(2, 6), Domino(3, 3), Domino(3, 4), Domino(3, 5), Domino(3, 6), Domino(4, 4), Domino(4, 5), Domino(4, 6), Domino(5, 5), Domino(5, 6), Domino(6, 6)]
# Initializes the game state and variables
def init_game():
global player_dominoes, computer_dominoes, boneyard, current_player, board, player_score, computer_score
player_dominoes = [] # Initializes an empty list to store the player's dominoes
computer_dominoes = [] # Initializes an empty list to store the computer's dominoes
boneyard = list(dominoes) # Creates a copy of the dominoes list to serve as the boneyard
random.shuffle(boneyard) # Shuffles the boneyard randomly
for _ in range(7): # Deals 7 dominoes to the player and the computer from the boneyard
player_dominoes.append(boneyard.pop()) # Removes a domino from the boneyard and adds it to the player's hand
computer_dominoes.append(boneyard.pop()) # Removes a domino from the boneyard and adds it to the computer's hand
current_player = "player" # Sets the current player to the player
board = [] # Initializes an empty list to represent the game board
setup_board(board, boneyard) # Sets up the initial state of the board
player_score = 0 # Initializes the player's score to 0
computer_score = 0 # Initializes the computer's score to 0
def setup_board(board, boneyard): # Sets up the initial state of the game board
doubles = [domino for domino in boneyard if domino.value1 == domino.value2] # Finds all double dominoes in the boneyard
if doubles: # If there are double dominoes available
board.append(doubles.pop()) # Adds a double domino to the board
boneyard.remove(board[0]) # Removes the added domino from the boneyard
else: # If there are no double dominoes available
board.append(boneyard.pop()) # Adds a random domino to the board
def make_move(domino): # Validates and executes the player's move
global player_dominoes, computer_dominoes, current_player, board, player_score, computer_score
if valid_move(domino, board): # Checks if the chosen domino can be played legally
player_dominoes.remove(domino) # Removes the chosen domino from the player's hand
add_to_board(domino, board) # Adds the chosen domino to the board
if not player_dominoes: # If the player has no more dominoes left
player_score += sum(d.value1 + d.value2 for d in computer_dominoes) # Calculates the player's score
show_result("player_wins", player_score, computer_score) # Displays the result
return # Exits the function
current_player = "computer" # Switches the current player to the computer
computer_move() # Executes the computer's move
else: # If the chosen move is invalid
renpy.notify("Invalid move. Please choose a domino that matches the ends of the board.") # Notifies the player
def computer_move(): # Executes the computer's move
global player_dominoes, computer_dominoes, current_player, board, player_score, computer_score
valid_moves = [domino for domino in computer_dominoes if valid_move(domino, board)] # Finds all valid moves for the computer
if valid_moves: # If there are valid moves available
move = random.choice(valid_moves) # Chooses a random valid move
computer_dominoes.remove(move) # Removes the chosen domino from the computer's hand
add_to_board(move, board) # Adds the chosen domino to the board
if not computer_dominoes: # If the computer has no more dominoes left
computer_score += sum(d.value1 + d.value2 for d in player_dominoes) # Calculates the computer's score
show_result("computer_wins", player_score, computer_score) # Displays the result
return # Exits the function
current_player = "player" # Switches the current player to the player
else: # If there are no valid moves for the computer
current_player = "player" # Switches the current player to the player
def valid_move(domino, board): # Checks if a move is valid
if not board: # If the board is empty
return True # Any domino can be played
return domino.value1 in [board[0].value1, board[-1].value2] or domino.value2 in [board[0].value1, board[-1].value2] # Checks if the chosen domino matches either end of the board
def add_to_board(domino, board): # Adds a domino to the board
if not board: # If the board is empty
board.append(domino) # Adds the domino to the board
elif domino.value1 == board[0].value1: # If the domino matches the start of the board
board.insert(0, domino) # Inserts the domino at the start of the board
elif domino.value1 == board[-1].value2: # If the domino matches the end of the board
board.append(domino) # Appends the domino to the end of the board
elif domino.value2 == board[0].value1: # If the flipped domino matches the start of the board
board.insert(0, Domino(domino.value2, domino.value1)) # Inserts the flipped domino at the start of the board
else: # If the flipped domino matches the end of the board
board.append(Domino(domino.value2, domino.value1)) # Appends the flipped domino to the end of the board
def show_result(winner, player_score, computer_score): # Displays the game result
renpy.hide_screen("domino_game") # Hides the domino game screen
if winner == "player_wins": # If the player wins
renpy.notify(f"You won! Your score: {player_score}, Computer score: {computer_score}") # Notifies the player
else: # If the computer wins
renpy.notify(f"Computer won! Your score: {player_score}, Computer score: {computer_score}") # Notifies the player
renpy.call_in_new_context("restart_game") # Calls the restart_game label in a new context
# Defines the domino_game screen
screen domino_game:
vbox: # Arranges children vertically
text "Player Score: [player_score]" # Displays the player's score
text "Computer Score: [computer_score]" # Displays the computer's score
null height 20 # Adds a space for layout
hbox: # Arranges children horizontally
for domino in board: # Iterates over each domino on the board
text str(domino) # Displays the string representation of the domino
null height 20 # Adds a space for layout
text "Your Dominoes:" # Displays a label for the player's dominoes
hbox: # Arranges children horizontally
for domino in player_dominoes: # Iterates over each domino in the player's hand
textbutton str(domino) action make_move(domino) # Displays the domino as a button to make a move
null height 20 # Adds a space for layout
text "Computer's Dominoes:" # Displays a label for the computer's dominoes
hbox: # Arranges children horizontally
for domino in computer_dominoes: # Iterates over each domino in the computer's hand
text str(domino) # Displays the string representation of the domino
null height 20 # Adds a space for layout
textbutton "Restart" action init_game() # Displays a button to restart the game and calls the init_game function
label start:
scene bg room
"Welcome to the Domino Game!"
$ init_game()
$ renpy.show_screen("domino_game")
"test"
label restart_game:
"pause"
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 117, in script
pause 1.0
File "renpy/common/000statements.rpy", line 460, in execute_pause
renpy.pause(delay)
Exception: renpy.restart_interaction() was called 100 times without processing any input.
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 117, in script
pause 1.0
File "C:\renpy-8.0.0-sdk\renpy\ast.py", line 1968, in execute
self.call("execute")
File "C:\renpy-8.0.0-sdk\renpy\ast.py", line 1950, in call
return renpy.statements.call(method, parsed, *args, **kwargs)
File "C:\renpy-8.0.0-sdk\renpy\statements.py", line 349, in call
return method(parsed, *args, **kwargs)
File "renpy/common/000statements.rpy", line 460, in execute_pause
renpy.pause(delay)
File "C:\renpy-8.0.0-sdk\renpy\exports.py", line 1661, in pause
rv = renpy.ui.interact(mouse='pause', type='pause', roll_forward=roll_forward, pause=delay, pause_modal=modal)
File "C:\renpy-8.0.0-sdk\renpy\ui.py", line 301, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "C:\renpy-8.0.0-sdk\renpy\display\core.py", line 2163, in interact
raise Exception("renpy.restart_interaction() was called 100 times without processing any input.")
Exception: renpy.restart_interaction() was called 100 times without processing any input.
Windows-10-10.0.19045 AMD64
Ren'Py 8.2.0.24012702
domino_test 1.0
Mon Apr 29 22:51:10 2024
please help me