Hanish101 commited on
Commit
2ccffd3
·
1 Parent(s): 14f0a98

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +58 -0
main.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pygame
2
+ from checkers.constants import WIDTH, HEIGHT, SQUARE_SIZE, RED, WHITE
3
+ from checkers.game import Game
4
+ from minimax.algorithm import minimax
5
+ from checkers.board import Board
6
+ from minimax.algorithm import get_all_moves
7
+
8
+ FPS = 60
9
+
10
+ WIN = pygame.display.set_mode((WIDTH, HEIGHT))
11
+ pygame.display.set_caption('Checkers')
12
+
13
+ def get_row_col_from_mouse(pos):
14
+ x, y = pos
15
+ row = y // SQUARE_SIZE
16
+ col = x // SQUARE_SIZE
17
+ return row, col
18
+
19
+ def main():
20
+ run = True
21
+ clock = pygame.time.Clock()
22
+ game = Game(WIN)
23
+
24
+ while run:
25
+ clock.tick(FPS)
26
+ if game.turn == WHITE:
27
+ moves = get_all_moves(game.get_board(),WHITE, game)
28
+ print(moves)
29
+ if not moves:
30
+ print("RED WON")
31
+ moves = get_all_moves(game.get_board(), RED, game)
32
+ print(moves)
33
+ if not moves:
34
+ print("WHITE WON")
35
+ value, new_board = minimax(game.get_board(), 4, WHITE, game)
36
+ game.ai_move(new_board)
37
+
38
+ if game.winner() != None:
39
+ if game.winner() == WHITE:
40
+ print('WHITE WON')
41
+ else:
42
+ print("RED WON")
43
+ run = False
44
+
45
+ for event in pygame.event.get():
46
+ if event.type == pygame.QUIT:
47
+ run = False
48
+
49
+ if event.type == pygame.MOUSEBUTTONDOWN:
50
+ pos = pygame.mouse.get_pos()
51
+ row, col = get_row_col_from_mouse(pos)
52
+ game.select(row, col)
53
+
54
+ game.update()
55
+
56
+ pygame.quit()
57
+
58
+ main()