def MakeBoard(p1, p2): iterations = 1 depth = 3 rows, cols = 10, 10 gm = game_manager.GameManager(rows, cols, player.makePlayer(p1, 'x', depth), player.makePlayer(p2, 'o', depth), True) return gm
def play(build_order): start_time = time.time() stats_list = [] gm = game_manager.GameManager() gm.start() lives = 40 build_order_index = 0 while lives > 0 and build_order_index < len(build_order): step = build_order[build_order_index] if gm.can_afford_tower(step.tower_type): gm.build_tower(step.tower_type, step.coords) build_order_index += 1 print(step) time.sleep(0.1) gm.click_start_round() stats = gm.get_stats() lives = stats[2] stats_list.append((time.time() - start_time, stats)) if (lives > 0): print("Got to end of build order") while lives > 0: time.sleep(0.1) gm.click_start_round() stats = gm.get_stats() lives = stats[2] stats_list.append((time.time() - start_time, stats)) gm.end() end_time = stats_list[-1][0] return end_time, build_order_index, stats_list
def makeGame(self, size, player1, player2, depth): gm = game_manager.GameManager(size, size, makePlayer(player1, 'x', depth), makePlayer(player2, 'o', depth), False) signal.signal(signal.SIGABRT, gm.interrupt) signal.signal(signal.SIGINT, gm.interrupt) signal.signal(signal.SIGQUIT, gm.interrupt) signal.signal(signal.SIGALRM, gm.interrupt) return gm
def MakeBoard(p1, p2): iterations = 1 depth = 3 rows, cols = 10, 10 gm = game_manager.GameManager(rows, cols, player.makePlayer(p1, 'x', depth), player.makePlayer(p2, 'o', depth), True) signal.signal(signal.SIGABRT, gm.interrupt) signal.signal(signal.SIGINT, gm.interrupt) signal.signal(signal.SIGQUIT, gm.interrupt) return gm
def __init__(self, username, client_id, token, channel): self.client_id = client_id self.token = token self.channel = '#' + channel self.streamer_username = username # True if drink command is enabled, false if disabled self.drink_enabled = False # used for gamble command, any number greater than or equal to this is a win self.gamble_percentage = 51 # map command name to timeout in minutes self.command_timeouts = {'drink': 15} # holds commands that have time before they can be executed again self.commands_in_timeout = {} self.game_manager = game_manager.GameManager() # Get the channel id, we will need this for v5 API calls url = 'https://api.twitch.tv/kraken/users?login='******'Client-ID': client_id, 'Accept': 'application/vnd.twitchtv.v5+json' } r = requests.get(url, headers=headers).json() self.channel_id = r['users'][0]['_id'] print(r) sys.stdout.flush() # Create IRC bot connection server = 'irc.chat.twitch.tv' port = 6667 print('Connecting to ' + server + ' on port ' + str(port) + '...') sys.stdout.flush() irc.bot.SingleServerIRCBot.__init__(self, [(server, port, 'oauth:' + token)], username, username)
import pygame, sprite, colors, game_manager pygame.init() screen_width = 1200 screen_height = 700 screen = pygame.display.set_mode((screen_width, screen_height)) clock = pygame.time.Clock() gm = game_manager.GameManager(screen) #Draw all images on the screen done = False while not done: #Handle events and inputs for event in pygame.event.get(): if event.type == pygame.QUIT: done = True elif event.type == pygame.KEYDOWN: #Press enter to attack with current character if event.key == pygame.K_RETURN: gm.startAnimation() #Press escape to quit elif event.key == pygame.K_ESCAPE: done = True screen.fill(colors.black) gm.update() gm.draw() pygame.display.flip() #Delay to get 60 fps clock.tick(60)
def __init__(self, *args, **kwargs): super(GameWindow, self).__init__(*args, **kwargs) self.has_exit = False self.playerManager = None self.gameManager = game_manager.GameManager(self)
Add in little islands with cannons to defeat. Implement splash in the water. https://www.youtube.com/watch?v=SO7FFteErWs ''' import boat, game_manager from functions import * pygame.init() clock = pygame.time.Clock() surface = pygame.display.set_mode((screen_width, screen_height)) gm = game_manager.GameManager() player = boat.Boat() done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True elif event.type == pygame.KEYDOWN: print(event.key) if event.key == pygame.K_ESCAPE: done = True if event.key == 32: #space bar player.jump() elif event.type == pygame.MOUSEBUTTONUP:
- jquery.js - used for web page programming and is a req for chessboard.js - chessboard.js - used for client side chess board visualization and interactions - chess.js - used as a chess engine on the user side to calculate valid moves and prevent invalid ones - socket.io.js - used for the client side socketio communications """ # flask app config and instance creation app = Flask("Chess AI", template_folder="templates", static_folder="static") app.config['SECRET_KEY'] = secrets.token_urlsafe(32) # socketIO config socket_io = SocketIO(app, async_mode='threading') # create manager = gm.GameManager() # thread pool pool = ThreadPoolExecutor(max_workers=32) @app.route('/') def homepage(): return render_template("intro-page.html") @app.route('/player-vs-ai') def player_vs_ai(): return render_template("choose-player-vs-ai.html")
def initialize_game_manager(self): self.game_manager = game_manager.GameManager(self) self.game_manager.update()
def makeGame(self, size, player1, player2, depth, script=None): gm = game_manager.GameManager(size, size, makePlayer(player1, 'x', depth), makePlayer(player2, 'o', depth), script, True) return gm
def main(): start = time.time() recordofai = [] #used to store ai over various jumps player_amount = 0 ai_amount = 2 for iteration_counter in range(0, iterations): ai_file = open("ai2.txt", "r") ai2_behaviour = ai_file.readlines() for dd in range(0, len(ai2_behaviour)): ai2_behaviour[dd] = float(ai2_behaviour[dd]) ai_file.close() for jumpcounter in range( 1, jumps + 1 ): #repeat for how many times the program should try to improve the ai win_array = [ ] #this list will contain how often the tested ai won against it's oppponent. jump_array = [ -1, 0, 1 ] #the ai's behaviour is tested around it's current value with this list. for gg in range(0, len(jump_array)): jump_array[gg] = jump_array[gg] * (1 - jumpcounter / jumps) + 0.1 #here the ai tries 81 different behaviours surrounding the base behaviour. for ww in jump_array: for xx in jump_array: for yy in jump_array: for zz in jump_array: ai_file = open("ai1.txt", "r") ai1_behaviour = ai_file.readlines() ai_file.close() ai1_behaviour[0] = float(ai1_behaviour[0]) + ww ai1_behaviour[1] = float(ai1_behaviour[1]) + xx ai1_behaviour[2] = float(ai1_behaviour[2]) + yy ai1_behaviour[3] = float(ai1_behaviour[3]) + zz win_counter = 0 #and plays games with each of the 81 behaviours for game_counter in range(0, games): #allow the user to choose the amount of players in the game #player_amount=-1 #ai_amount=-1 # while (player_amount == -1): # try: # player_amount=int(input("how many players will be playing?")) # if player_amount<0: # print("that is silly") # player_amount=-1 # elif player_amount==0: # print("computers can have fun too") # break # # except ValueError: # print("Please return a number.") # player_amount = -1 # # while (ai_amount == -1): # try: # ai_amount=int(input("how many ai's will be playing?")) # if ai_amount<0: # print("that is silly") # ai_amount=-1 # elif ai_amount==0: # print("no computers, fine") # break # # except ValueError: # print("Please return a number.") # player_amount = -1 if ai_amount == 0 and player_amount == 0: print( "no players and no AI's make for no game" ) else: #set up players players = [] # for x in range(0,player_amount): # players.append(player.Player(x)) players.append( ai_player.Ai_player( 0 + player_amount, float(ai1_behaviour[0]), float(ai1_behaviour[1]), float(ai1_behaviour[2]), float(ai1_behaviour[3]))) players.append( ai_player.Ai_player( 1 + player_amount, float(ai2_behaviour[0]), float(ai2_behaviour[1]), float(ai2_behaviour[2]), float(ai2_behaviour[3]))) #set up a list containing the companies companies_ingame = [] for x in range(0, len(companies_setup_money)): value = companies_setup_money[x] companies_ingame.append( company.Company( value, 1, player_amount + ai_amount)) for z in range( 0, len(companies_setup_victory)): value = companies_setup_victory[z] companies_ingame.append( company.Company( value, 2, player_amount + ai_amount)) #play until a player has earned enough money to win the game. turn_counter = 0 manager = game_manager.GameManager( players, companies_ingame) most_victory_points = 0 while (most_victory_points < win_condition ) and turn_counter <= 100: manager.investmentphase() manager.rewardphase() turn_counter += 1 for x in range(0, len(players)): most_victory_points = max( most_victory_points, players[x].victory_points) #check who won who_won_string = "\nPlayer " for y in range(0, len(players)): if players[ y].victory_points == most_victory_points: who_won_string = who_won_string + str( y + 1) + " " who_won = y who_won_string = who_won_string + "won the game.\n" print(who_won_string) if who_won == 0: win_counter += 1 print("The final score was:\n") for x in range(0, len(players)): print("Player " + str(x + 1) + " had " + str(players[x].victory_points) + " victory points.") #here a record is made of the results of the games played and the behaviour involved result_array = [win_counter, ai1_behaviour] win_array.append(result_array) #the behaviour that scored best is taken as the new base behaviour to test around maxi = 0 winning_iteration = 0 for cc in range(0, len(win_array)): if win_array[cc][0] > maxi: maxi = win_array[cc][0] winning_iteration = cc ai1_behaviour = win_array[winning_iteration][1] recordofai.append(ai1_behaviour) #and is written in the ai file ai_file = open("ai1.txt", "w") for qq in range(0, len(ai1_behaviour)): ai1_behaviour[qq] = str(ai1_behaviour[qq]) ai_file.write(ai1_behaviour[qq] + "\n") ai_file.close() ai_file = open("ai_record.txt", "a") for aa in range(0, len(ai1_behaviour)): ai_file.write(ai1_behaviour[aa] + "\n") ai_file.write(str(maxi / games) + "\n") ai_file.close() ai_file = open("ai2.txt", "w") for hh in range(0, len(ai1_behaviour)): ai_file.write(ai1_behaviour[hh] + "\n") ai_file.close() stop = time.time() print(stop - start) winsound.Beep(2500, 500)
large_font = pygame.font.SysFont('Arial', 48) small_font = pygame.font.SysFont('Arial', 24) def userInputToPlayer(player): keys = pygame.key.get_pressed() if keys[pygame.K_UP]: player.thrust() if keys[pygame.K_LEFT]: player.rotateLeft() if keys[pygame.K_RIGHT]: player.rotateRight() #Create game manager object to manage updating and moving everything gm = game_manager.GameManager(screen, 0) #Start on level 0 #Main loop done = False while not done: #Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: done = True elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: done = True #Press enter to reset game after death if event.key == pygame.K_RETURN and (gm.player.lives <= 0 or gm.victory): gm = game_manager.GameManager(screen, 0) #Reset to level 0