diff --git a/controller.py b/controller.py index c8c8574..07f9ec1 100644 --- a/controller.py +++ b/controller.py @@ -21,7 +21,6 @@ def __init__(self): axes = self.joysticks[i].get_numaxes() print(axes) - print(self.type) print(self.joysticks) def checkController(self): @@ -38,20 +37,20 @@ def isControllerEvent(self, event): ) def isControllerDropEvent(self, event): - if self.type[0] == "PS4 Controller": - if event.type == JOYBUTTONDOWN: - return (event.button == 12 or event.button == 0) - if event.type == JOYAXISMOTION: - return (abs(event.axis) == 5 and event.value == 1) - - else: - if event.type == JOYBUTTONDOWN: - return event.button == 0 - if event.type == JOYHATMOTION: - return event.value[1] == -1 - if event.type == JOYAXISMOTION: - return (abs(event.axis) == 5 and event.value == 1) - + if len(self.type) > 0: + if self.type[0] == "PS4 Controller": + if event.type == JOYBUTTONDOWN: + return event.button == 12 or event.button == 0 + if event.type == JOYAXISMOTION: + return abs(event.axis) == 5 and event.value == 1 + + else: + if event.type == JOYBUTTONDOWN: + return event.button == 0 + if event.type == JOYHATMOTION: + return event.value[1] == -1 + if event.type == JOYAXISMOTION: + return abs(event.axis) == 5 and event.value == 1 def get_x_pos(self, event): px_diff_hd = 109 # how much the chip will move each time @@ -140,54 +139,53 @@ def menu_action(self, event): if event.value == 1: self.Esc() - def check_event(self, event, menu:object,screen, clock): + def check_event(self, event, menu: object, screen, clock): px_diff_hd = 109 # how much the chip will move each time max_px_hd = 931 # max x position of the chip min_px_hd = 269 # min x position of the chip if self.type[0] == "PS4 Controller": - + # Press Buttons if event.type == JOYBUTTONDOWN: - if event.button == 1 or event.button == 6: - play_again = menu.run(screen,clock) + if event.button == 1 or event.button == 6: + play_again = menu.run(screen, clock) if not play_again: return play_again - # if event.button == 12 or event.button == 0: - # self.DropChip() + # if event.button == 12 or event.button == 0: + # self.DropChip() if event.button == 13 or event.button == 9: print("Move left") - self.x_hd -= px_diff_hd if self.x_hd - px_diff_hd >= min_px_hd else 0 + self.x_hd -= ( + px_diff_hd if self.x_hd - px_diff_hd >= min_px_hd else 0 + ) return self.x_hd - if event.button == 14 or event.button == 10: print("Move right") self.x_hd += px_diff_hd if self.x_hd + px_diff_hd < max_px_hd else 0 return self.x_hd - # Sticks PS4 if event.type == JOYAXISMOTION: if abs(event.axis) == 0: - if event.value > .7: + if event.value > 0.7: print("Move Right") - + self.x_hd += 5 if self.x_hd + 5 < max_px_hd else 0 return self.x_hd - - - if event.value < -.7: + + if event.value < -0.7: print("Move Left") - + self.x_hd -= 5 if self.x_hd - 5 >= min_px_hd else 0 return self.x_hd if abs(event.axis) == 4: if event.value == 1: - play_again = menu.run(screen,clock) + play_again = menu.run(screen, clock) if not play_again: return play_again @@ -197,55 +195,51 @@ def check_event(self, event, menu:object,screen, clock): # Press buttons if event.type == JOYBUTTONDOWN: - if event.button == 1 or event.button == 7: - play_again = menu.run(screen,clock) + if event.button == 1 or event.button == 7: + play_again = menu.run(screen, clock) if not play_again: return play_again if event.button == 4: print("Move left") - self.x_hd -= px_diff_hd if self.x_hd - px_diff_hd >= min_px_hd else 0 + self.x_hd -= ( + px_diff_hd if self.x_hd - px_diff_hd >= min_px_hd else 0 + ) return self.x_hd - if event.button == 5: print("Move right") self.x_hd += px_diff_hd if self.x_hd + px_diff_hd < max_px_hd else 0 return self.x_hd - - + # D-pad Xbox if event.type == JOYHATMOTION: if event.value[0] == 1: print("Move right") self.x_hd += px_diff_hd if self.x_hd + px_diff_hd < max_px_hd else 0 return self.x_hd - - + if event.value[0] == -1: print("Move left") - self.x_hd -= px_diff_hd if self.x_hd - px_diff_hd >= min_px_hd else 0 + self.x_hd -= ( + px_diff_hd if self.x_hd - px_diff_hd >= min_px_hd else 0 + ) return self.x_hd - - if event.type == JOYAXISMOTION: if abs(event.axis) == 0: - if event.value > .7: + if event.value > 0.7: print("Move Right") self.x_hd += 5 if self.x_hd + 5 < max_px_hd else 0 return self.x_hd - - - - if event.value < -.7: + + if event.value < -0.7: print("Move Left") self.x_hd -= 5 if self.x_hd - 5 >= min_px_hd else 0 return self.x_hd if abs(event.axis) == 4: if event.value == 1: - play_again = menu.run(screen,clock) + play_again = menu.run(screen, clock) if not play_again: return play_again - \ No newline at end of file diff --git a/main_screen.py b/main_screen.py index fc96c50..18ddd43 100644 --- a/main_screen.py +++ b/main_screen.py @@ -99,8 +99,6 @@ def main_screen(self, usernames: list, option="AI"): option, ) - print(player_turn) - if play_again != None: return play_again @@ -124,8 +122,6 @@ def main_screen(self, usernames: list, option="AI"): option, ) - print(player_turn) - if play_again != None: return play_again @@ -143,8 +139,6 @@ def main_screen(self, usernames: list, option="AI"): control.check_event(event, menu, screen, clock) if option == "AI" and player_turn % 2 == 1: - print(player_turn) - column, minimax_score = utilities.minimaxTree( matrix, 5, -math.inf, math.inf, True ) @@ -153,7 +147,6 @@ def main_screen(self, usernames: list, option="AI"): row = utilities.get_open_row(matrix, column) utilities.drop_piece(matrix, row, column, self.ai_chip) - print(matrix) if utilities.is_victory(matrix, self.ai_chip): utilities.draw_board(matrix, start_time, clock) diff --git a/utilities.py b/utilities.py index 2d8d976..4dbd0e3 100644 --- a/utilities.py +++ b/utilities.py @@ -196,7 +196,7 @@ def is_valid( turn += 1 if turn % 2 == 0: - chip = self.chip_1 + chip = self.chip_2 turn = 2 @@ -205,7 +205,7 @@ def is_valid( return turn, chip elif turn % 2 == 1: - chip = self.chip_2 + chip = self.chip_1 turn = 1