-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame_human.py
45 lines (32 loc) · 1.05 KB
/
game_human.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# This file is a human-playable version of 2048.
# Controls: W/A/S/D for up/down/left/right, followed by the enter key
from game import *
def main():
board = new_board()
while True:
print_board(board)
if is_board_lost(board):
print("No moves left. Game over.")
return
if is_board_won(board):
print("Congrats! You win!")
return
key = input()
left_board = push_board_left(board)
right_board = push_board_right(board)
up_board = push_board_up(board)
down_board = push_board_down(board)
if key == "a" and board != left_board:
board = left_board
add_cell(board)
if key == "d" and board != right_board:
board = right_board
add_cell(board)
if key == "w" and board != up_board:
board = up_board
add_cell(board)
if key == "s" and board != down_board:
board = down_board
add_cell(board)
if __name__ == "__main__":
main()