Exemplo n.º 1
0
def main():
	global board
	#Initialization
	# add pieces to board and print board. 
	board = grid.setup_board(board)
	grid.print_board(board)

	# game loop. Play till user decides to quit
	while grid.get_winner(board):
		
		human.get_choice() 
		ai.get_move()
		board = grid.check_knight(board)
Exemplo n.º 2
0
 def best_strategy(self, board, player, best_move, still_running):
     twoD = from_tournament_format(board)
     mv = ai.get_move(twoD, FROM_TOURNAMENT[player], best_move, still_running)
     if mv is None:
         print("BAD BAD BAD")
         exit()
         return -12
     intm = to_tournament_move(mv)
     best_move.value = intm
     return intm
Exemplo n.º 3
0
	def grid_button_clicked(self, event):
		
		x = ( int( (event.y - 2) / 64) )
		y = ( int( (event.x - 2) / 64) )
		
		if x > 4:
			x = 4
			
		if y > 4:
			y = 4
		
		if x < 0:
			x = 0
			
		if y < 0:
			y = 0		
		
		
		if self.cur_piece == '': # if you haven't picked a piece yet
				
			for e in self.human_state.dic: # loop thru human dict
				
				if self.human_state.board[x][y] == e: # if this clicked piece is one of yours!!!!
				
					self.output_text(ai.speak.get_speech(1))
					
					if sound.get() == 1:
						audio.play_music("pickup.wav")
					
					self.cur_piece = self.human_state.board[x][y] # set it current piece (so we can go to phase 2)
					self.last_x = x # save our position
					self.last_y = y # ^ ye
					
					#self.output_text('You selected ' + self.cur_piece + ' at (' + str(x) +  ',' +str(y) + ')') # wut dis do? lol output
					
					
		elif self.cur_piece == self.human_state.board[x][y]: # if you click on the piece you already selected, deselect it!
		
			if sound.get() == 1:
				audio.play_music("putdown.wav")	
				
			#self.output_text('You deselected ' + self.cur_piece) 		
			
			self.cur_piece = '' # i aint select no darn piece
			
			
		else: # else
			
			
				
			if self.human_state.validate_location(self.last_x, self.last_y, x, y, self.cur_piece, ai.state.board): # if valid move
			
				# get the ai move first (so it doesn't cheat ;) )
				dic_ai, piece_ai = ai.get_move(self.human_state.dic)

				# if ai cant find any moves, it must be stalemate (I trust my ai)
				if dic_ai == False:
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(7) + '\n\nStalemate! \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit()
					
				# jus sum outbuts
				#self.output_text('You moved ' + self.cur_piece + ' to (' + str(x) +  ',' +str(y) + ')')

				# move human piece
				self.human_state.dic = self.human_state.move_piece(x,y,self.cur_piece, self.human_state.dic)
				
				# now actually make the moves (let the carnage begin \(>-<)/ )
				self.human_state.dic, dic_ai, msg = grid.finalize_move( self.human_state.dic, dic_ai, self.cur_piece, piece_ai)
				#print(self.human_state.dic, dic_ai)
				
				if msg != '':
					self.output_text(msg)
				
				if sound.get() == 1:
					audio.play_music("alert.wav")
					
				# check if the peasants are worthy of knighthood
				dic_ai, mb = grid.check_knight(dic_ai)
				
				# make the boards used for display from dicts
				self.human_state.board = grid.recreate_grid(self.human_state.dic)
				ai.state.board = grid.recreate_grid(ai.state.dic)
				
				# if you have 2 knights, put random
				if mb != 'none':
					
					x = random.randint(0, grid.GRID_HEIGHT - 1)
					y = random.randint(0, grid.GRID_WIDTH - 1)

					while self.human_state.board[x][y] != grid.b and ai.state.board[x][y] != grid.b:
						x = random.randint(0, grid.GRID_HEIGHT - 1)
						y = random.randint(0, grid.GRID_WIDTH - 1)
						
					dic_ai[mb] = [x,y]
					self.output_text('AI relocated ' + mb + ' to (' + str(x) +  ',' +str(y) + ')')
					
				# k
				self.human_state.dic, mb = grid.check_knight(self.human_state.dic)
				
				# if you have 2 knights, ask to relocate
				if mb != 'none':
					a = Popup_Knight(self.root, mb, self.human_state.dic, self)
					
				# send the ai dictionary back (it got updated)
				ai.dic_ai = dic_ai
				
				# make the boards used for display from dicts
				self.human_state.board = grid.recreate_grid(self.human_state.dic)
				ai.state.board = grid.recreate_grid(ai.dic_ai)
				
				#self.update_grid()
					
				# if WE HAVE A WINNER!
				won = grid.get_winner(self.human_state.dic, ai.dic_ai)
				
				if won == 'ai': # if my great ai won (and it will ;) )
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(5) + '\n\nYou Lose! :( \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit()
					
				elif won == 'human': # if you fluked out somehow :p
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(6) + '\n\nYou win! :) \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit()
						
				elif won == 'draw': # if it is stalemate, Nova!
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(7) + '\n\nStalemate!!! \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit()
				
				#print(grid.recreate_grid(self.human_state.dic))
				#print(grid.recreate_grid(ai.dic_ai))
				
				self.cur_piece = '' # you already moved so why u need dat piece homie?
				
			else:
				
				self.output_text('You earned a penalty point') # oh no!!!	
				self.output_text(ai.speak.get_speech(1))
				self.human_state.penalty += 1 # stacks on stacks
				self.bac_canvas.itemconfig('penalty', image = self.spr_penalty)
				#audio.play_beep("SystemHand") #replace
				
				if self.human_state.penalty == 2: # red card + 6 fouls :/
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(5) + '\n\nYou Lose! :( \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit() # and your kicked out! <(;-;)>
Exemplo n.º 4
0
	def grid_button_clicked(self, event):
		
		x = ( int( (event.y - 2) / 64) )
		y = ( int( (event.x - 2) / 64) )
		
		#print('hey',self.cur_piece)
		if self.cur_piece == '': # if you haven't picked a piece yet
			audio.play_music("pickup.wav")
			for e in self.dic_human: # loop thru human dict
				
				if self.human_board.board[x][y] == e: # if this clicked piece is one of yours!!!!
					
					self.cur_piece = self.human_board.board[x][y] # set it current piece (so we can go to phase 2)
					self.last_x = x # save our position
					self.last_y = y # ^ ye
					
					self.output_text('You selected ' + self.cur_piece + ' at (' + str(x) +  ',' +str(y) + ')') # wut dis do? lol output
					
					
		elif self.cur_piece == self.human_board.board[x][y]: # if you click on the piece you already selected, deselect it!
			audio.play_music("putdown.wav")	
			self.output_text('You deselected ' + self.cur_piece) 		
			
			self.cur_piece = '' # i aint select no darn piece
			
			
		else: # else
			audio.play_music("alert.wav")
			if self.human_board.validate_location(self.last_x, self.last_y, x, y, self.cur_piece, ai.board.board): # if valid move
			
				# get the ai move first (so it doesn't cheat ;) )
				dic_ai, piece_ai = ai.get_move(self.dic_human)

				# if ai cant find any moves, it must be stalemate (I trust my ai)
				if dic_ai == False:
					messagebox.showinfo('', 'Stalemate!')
					sys.exit() # will be replaced by restart
					
				# jus sum outbuts
				self.output_text('You moved ' + self.cur_piece + ' to (' + str(x) +  ',' +str(y) + ')')

				# move human piece
				self.dic_human = self.human_board.move_piece(x,y,self.cur_piece, self.dic_human)
				
				# now actually make the moves (let the carnage begin \(>-<)/ )
				self.dic_human, dic_ai = grid.finalize_move( self.dic_human, dic_ai, self.cur_piece, piece_ai)
				#print(self.dic_human, dic_ai)
				
				# check if the peasants are worthy of knighthood
				dic_ai, mb = grid.check_knight(dic_ai)
				
				# make the boards used for display from dicts
				self.human_board.board = grid.recreate_grid(self.dic_human)
				ai.board.board = grid.recreate_grid(ai.dic_ai)
				
				# if you have 2 knights, put random
				if mb != 'none':
					
					x = random.randint(0, grid.GRID_HEIGHT)
					y = random.randint(0, grid.GRID_WIDTH)
					#if the new picked locations are not valid, repick
					while self.human_board.board[x][y] != grid.b and ai.board.board[x][y] != grid.b:
						x = random.randint(0, grid.GRID_HEIGHT)
						y = random.randint(0, grid.GRID_WIDTH)
					
					#change the location of the pawn in the ai dictionary		
					dic_ai[mb] = [x,y]
					self.output_text('AI relocated ' + mb + ' to (' + str(x) +  ',' +str(y) + ')')
					
				# k
				self.dic_human, mb = grid.check_knight(self.dic_human)
				
				# if you have 2 knights, ask to relocate
				if mb != 'none':
					a = Popup_Knight(self.root, mb, self.dic_human, self)
					
				# send the ai dictionary back (it got updated)
				ai.dic_ai = dic_ai
				
				# make the boards used for display from dicts
				self.human_board.board = grid.recreate_grid(self.dic_human)
				ai.board.board = grid.recreate_grid(ai.dic_ai)
				
				#self.update_grid()
					
				# if WE HAVE A WINNER!
				won = grid.get_winner(self.dic_human, ai.dic_ai)
				
				if won == 'ai': # if my great ai won (and it will ;) )
				
					messagebox.showinfo('', 'You lose! :(')
					sys.exit()
					
				elif won == 'human': # if you fluked out somehow :p
				
					messagebox.showinfo(' ', 'You Win! :)')
					sys.exit()

					

					self.root.destroy()

				elif won == 'draw': # if it is stalemate, Nova!
				
					messagebox.showinfo('', 'Stalemate!')
					sys.exit()
				
				#print(grid.recreate_grid(self.dic_human))
				#print(grid.recreate_grid(ai.dic_ai))
				
				self.cur_piece = '' # you already moved so why u need dat piece homie?
			
			#if the location picked is invalid.	
			else:
			
				global penalty # you goin to penalty!!!!!!!!
				
				self.output_text('You earned a penalty point') # oh no!!!	
				
				penalty += 1 # stacks on stacks
				
				if penalty == 2: # with 2 invalid moves you lose
				
					messagebox.showinfo(' ', 'You Lose! :(') # you lose
					sys.exit() # and your kicked out! <(;-;)>
Exemplo n.º 5
0
def run_our_strategy(board, color, move):
    runnin = Value('i', 1)
    get_move(board, color, move, runnin)
    print("DON GET MOV")
Exemplo n.º 6
0
def run_on_main_thread(board, player):
    move = Value('i', 11)
    running = Value('i', 1)
    get_move(board, player, move, running)
    return from_tournament_move(move.value)
Exemplo n.º 7
0
    def grid_button_clicked(self, event):

        x = (int((event.y - 2) / 64))
        y = (int((event.x - 2) / 64))

        if x > 4:
            x = 4

        if y > 4:
            y = 4

        if x < 0:
            x = 0

        if y < 0:
            y = 0

        if self.cur_piece == '':  # if you haven't picked a piece yet

            for e in self.human_state.dic:  # loop thru human dict

                if self.human_state.board[x][
                        y] == e:  # if this clicked piece is one of yours!!!!

                    self.output_text(ai.speak.get_speech(1))

                    if sound.get() == 1:
                        audio.play_music("pickup.wav")

                    self.cur_piece = self.human_state.board[x][
                        y]  # set it current piece (so we can go to phase 2)
                    self.last_x = x  # save our position
                    self.last_y = y  # ^ ye

                    #self.output_text('You selected ' + self.cur_piece + ' at (' + str(x) +  ',' +str(y) + ')') # wut dis do? lol output

        elif self.cur_piece == self.human_state.board[x][
                y]:  # if you click on the piece you already selected, deselect it!

            if sound.get() == 1:
                audio.play_music("putdown.wav")

            #self.output_text('You deselected ' + self.cur_piece)

            self.cur_piece = ''  # i aint select no darn piece

        else:  # else

            if self.human_state.validate_location(
                    self.last_x, self.last_y, x, y, self.cur_piece,
                    ai.state.board):  # if valid move

                # get the ai move first (so it doesn't cheat ;) )
                dic_ai, piece_ai = ai.get_move(self.human_state.dic)

                # if ai cant find any moves, it must be stalemate (I trust my ai)
                if dic_ai == False:

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(7) +
                            '\n\nStalemate! \n Would you like to play again?'):
                        self.new_game()
                    else:  # you lose
                        sys.exit()

                # jus sum outbuts
                #self.output_text('You moved ' + self.cur_piece + ' to (' + str(x) +  ',' +str(y) + ')')

                # move human piece
                self.human_state.dic = self.human_state.move_piece(
                    x, y, self.cur_piece, self.human_state.dic)

                # now actually make the moves (let the carnage begin \(>-<)/ )
                self.human_state.dic, dic_ai, msg = grid.finalize_move(
                    self.human_state.dic, dic_ai, self.cur_piece, piece_ai)
                #print(self.human_state.dic, dic_ai)

                if msg != '':
                    self.output_text(msg)

                if sound.get() == 1:
                    audio.play_music("alert.wav")

                # check if the peasants are worthy of knighthood
                dic_ai, mb = grid.check_knight(dic_ai)

                # make the boards used for display from dicts
                self.human_state.board = grid.recreate_grid(
                    self.human_state.dic)
                ai.state.board = grid.recreate_grid(ai.state.dic)

                # if you have 2 knights, put random
                if mb != 'none':

                    x = random.randint(0, grid.GRID_HEIGHT - 1)
                    y = random.randint(0, grid.GRID_WIDTH - 1)

                    while self.human_state.board[x][
                            y] != grid.b and ai.state.board[x][y] != grid.b:
                        x = random.randint(0, grid.GRID_HEIGHT - 1)
                        y = random.randint(0, grid.GRID_WIDTH - 1)

                    dic_ai[mb] = [x, y]
                    self.output_text('AI relocated ' + mb + ' to (' + str(x) +
                                     ',' + str(y) + ')')

                # k
                self.human_state.dic, mb = grid.check_knight(
                    self.human_state.dic)

                # if you have 2 knights, ask to relocate
                if mb != 'none':
                    a = Popup_Knight(self.root, mb, self.human_state.dic, self)

                # send the ai dictionary back (it got updated)
                ai.dic_ai = dic_ai

                # make the boards used for display from dicts
                self.human_state.board = grid.recreate_grid(
                    self.human_state.dic)
                ai.state.board = grid.recreate_grid(ai.dic_ai)

                #self.update_grid()

                # if WE HAVE A WINNER!
                won = grid.get_winner(self.human_state.dic, ai.dic_ai)

                if won == 'ai':  # if my great ai won (and it will ;) )

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(5) +
                            '\n\nYou Lose! :( \n Would you like to play again?'
                    ):
                        self.new_game()
                    else:  # you lose
                        sys.exit()

                elif won == 'human':  # if you fluked out somehow :p

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(6) +
                            '\n\nYou win! :) \n Would you like to play again?'
                    ):
                        self.new_game()
                    else:  # you lose
                        sys.exit()

                elif won == 'draw':  # if it is stalemate, Nova!

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(7) +
                            '\n\nStalemate!!! \n Would you like to play again?'
                    ):
                        self.new_game()
                    else:  # you lose
                        sys.exit()

                #print(grid.recreate_grid(self.human_state.dic))
                #print(grid.recreate_grid(ai.dic_ai))

                self.cur_piece = ''  # you already moved so why u need dat piece homie?

            else:

                self.output_text('You earned a penalty point')  # oh no!!!
                self.output_text(ai.speak.get_speech(1))
                self.human_state.penalty += 1  # stacks on stacks
                self.bac_canvas.itemconfig('penalty', image=self.spr_penalty)
                #audio.play_beep("SystemHand") #replace

                if self.human_state.penalty == 2:  # red card + 6 fouls :/

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(5) +
                            '\n\nYou Lose! :( \n Would you like to play again?'
                    ):
                        self.new_game()
                    else:  # you lose
                        sys.exit()  # and your kicked out! <(;-;)>