-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (34 loc) · 918 Bytes
/
Copy pathmain.py
File metadata and controls
42 lines (34 loc) · 918 Bytes
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
from c2048 import C2048, Move
game = C2048()
print(game)
# clones the game, so the original doesn't get affected
down = game.clone_move(Move.Down)
print(down)
# moves up, changing the original
game.move(Move.Left)
print(game)
# Prints all the moves done
print(game.moves)
# The main loop should be like this
game = C2048()
while True:
print(f"Score: {game.score()}")
print(game)
# pick a random move
move = Move.random()
game.move(move)
if game.has_moved:
# Probability of getting a 2
game.spawn_tile(0.9)
# resets the game.has_moved
game.reset()
if game.is_win():
print("You win, max tile: ", game.highest())
break
elif game.is_lose():
print("You lose, max tile: ", game.highest())
break
# to get the all the moves
# print(f"Moves: {game.moves}")
# to get all the tile spawns
# print(f"Spawns: {game.spawns}")