MicahWW / Python-Games

2 stars 0 forks source link

Terminal game relies the ICON attributes being set what will be displayed #45

Closed MicahWW closed 1 year ago

MicahWW commented 1 year ago

With the below being set in the init of Tic-Tac-Toe when playing in Tic-Tac-Toe in the terminal it takes advantage of it being the characters that it will be printed out, even with the later added feature of changing the icons as it changes those variables directly.

# Player Icons
self.BLANK_POS_ICON = " "
self.PLAYER_0_ICON = "X"
self.PLAYER_1_ICON = "O"

By changing these to be a static representation of each icon, like a number, the terminal display function can then use variables to know what to map those static representations into. This also has the added benefit of other interfaces of the game (GUI, web through REST) having a standard way of understanding the data they receive and they can display how they want, just like the terminal game.

codyswanner commented 1 year ago

My preference for numbers:

# Player Icons
self.BLANK_POS_ICON = 0
self.PLAYER_0_ICON = 1
self.PLAYER_1_ICON = -1

With this setup, "zero" is intuitively "blank space."

This also opens up a possibility for checking win scenarios -- summing each of the rows, cols and diags, any that add up to 3 are a player 0 win, and any that add up to -3 are player 1 wins. This could also be helpful for the bot to decide which spaces it should play in. Implementing this would require some changes to bot_move and check_board, but may simplify operations in those functions.