Skip to content

Instantly share code, notes, and snippets.

@a-shebl
Created October 30, 2022 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-shebl/80caf37598c77ceaafdbfb0f2d86396f to your computer and use it in GitHub Desktop.
Save a-shebl/80caf37598c77ceaafdbfb0f2d86396f to your computer and use it in GitHub Desktop.
Xo game using dictionary
Board_info = {"Top-L":" ","Top-M":" ","Top-R":" ",
"Mid-L":" ","Mid-M":" ","Mid-R":" ",
"Low-L":" ","Low-M":" ","Low-R":" ",}
def shape(board):
print(board["Top-L"] + "|" +board["Top-M"] +"|" +board["Top-R"])
print("-----")
print(board["Mid-L"] + "|" +board["Mid-M"] +"|" +board["Mid-R"])
print("-----")
print(board["Low-L"] + "|" +board["Low-M"] +"|" +board["Low-R"])
turn = "x"
for i in range(9):
shape(Board_info)
print("Turn for " + turn)
move = input("which space")
Board_info[move] = turn
if turn == "x":
turn = "o"
else:
turn = "x"
if Board_info["Top-L"] and Board_info["Top-M"] and Board_info["Top-R"] == "x":
print("x wins")
elif Board_info["Mid-L"] and Board_info["Mid-M"] and Board_info["Mid-R"] == "x":
print("x wins")
elif Board_info["Low-L"] and Board_info["Low-M"] and Board_info["Low-R"] == "x":
print("x wins")
print(shape(Board_info))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment