Beispiel #1
0
def grid_size():        #user can select size of connect 4 grid
        while True:
                print("\t1 = SMALL(5x4)\t 2 = Default(7x6)\t3 = Large(9x8)\n")
                print ("\t4 = Return to Mode Menu\n")
                try:            #try/except statement, prevents from python displaying error when excecuted
                        g =int(input("Enter the number of the grid you wish to play with: "))
                        print(" ")
                        if g == 1:                      #small connect 4 GUI grid  
                                g_gui = Grid_mode()     
                                g_gui.small_grid()
                                gui = g_gui
                                pause()
                                main()
                        elif g == 2:                    # standard 7x6 connect 4 GUI grid
                                b_gui = GameGUI()
                                b_gui.intialise_dynamic()
                                gui = b_gui
                                pause()
                                main()
                        elif g == 3:                    # large connect 4 GUI grid
                                g_gui = Grid_mode()
                                g_gui.large_grid()
                                gui = g_gui
                                pause()
                                main()
                        elif g == 4:
                                modes_menu()            #retruns to modes_menu
                                
                        else:
                                print("")
                                print("invalid menu option")
                                grid_size()
                except ValueError:                      # if user enters a value/number the print statement displayed
                    print("\nTry Again!!!")
def _run(width,
         height,
         playerA,
         playerB,
         depth=3,
         useDecisionTree=True,
         dynamicDepth=False):
    print "Running... "
    board = GameBoard(width, height, playerA, playerB, depth, useDecisionTree,
                      dynamicDepth)
    board.turn = 1
    board.scores = [0, 0]
    try:
        gui = GameGUI(board)
        print "Hello"
    except Exception as e:
        pass
Beispiel #3
0
def play(player_2_is_human, player_1_is_human, evaluate, search, max_depth,
         pause_for=0, gui_mode=False):
    """
    A game loop that has either a human player or the AI playing interactively
    against another human or the AI itself. Recall that player 2 plays first!

    :param player_2_is_human: True iff the a human is controlling player 2
    :type player_2_is_human: bool
    :param player_1_is_human: True iff the a human is controlling player 1
    :type player_1_is_human: bool
    :param evaluate: a function taking a state and an expanded state and
        returning a heuristic estimate of the state's utility for the current
        player
    :type evaluate: (array of bytes, dict(byte, char)) => numeric
    :param search: a search function taking a state, an expanded state, an
        evaluation function, a remaining depth, and returning a
        (<utility>, <move>) pair
    :type search: (array of bytes,
                   dict(byte, char),
                   (array of bytes, dict(byte, char)) => numeric,
                   int) => (numeric, (byte, byte))
    :param max_depth: the maximum search depth; must be at least 1
    :type max_depth: int
    :param pause_for: number of seconds to pause for after getting the move
        from the human player or the AI before actually making the move;
        defaults to 0
    :type pause_for: int or float
    :param gui_mode: should the game be played in gui mode? defaults to False
    :type gui_mode: bool
    """
    move_number, state, expanded_state = setup_game()
    if not gui_mode:
        while True:
            if play_ply(state, expanded_state, player_2_is_human, pause_for,
                        move_number, evaluate, search, max_depth):
                break
            if play_ply(state, expanded_state, player_1_is_human, pause_for,
                        move_number, evaluate, search, max_depth):
                break
            move_number += 1
    else:
        from gui import GameGUI
        GameGUI(evaluate, search, max_depth, player_1_is_human,
                player_2_is_human)
def _runStats(width,
              height,
              playerA,
              playerB,
              depth=3,
              useDecisionTree=True,
              dynamicDepth=False):
    line = "%d, %d, %s, %s, %d, %d, %d\n" % (
        width, height, playerA, playerB, depth, useDecisionTree, dynamicDepth)
    writeToStats(line, useDecisionTree)

    start = time.clock()
    board = GameBoard(width, height, playerA, playerB, depth, useDecisionTree,
                      dynamicDepth)
    board.turn = 1
    board.scores = [0, 0]
    try:
        gui = GameGUI(board)
    except Exception as e:
        pass
    end = time.clock()
    line = "%f\n\n" % (end - start)
    writeToStats(line, useDecisionTree)
Beispiel #5
0
#! /usr/bin/env python3

# SUGGESTION: use a "hash bang" to make your script executable
# https://stackoverflow.com/questions/2429511/why-do-people-write-the-usr-bin-env-python-shebang-on-the-first-line-of-a-pyt

import random
import sys
import time
import turtle

from constants import FISH
from gui import GameGUI
from game import Game

if __name__ == '__main__':

    game = Game(max_turns=10, fish_options=FISH, game_gui=GameGUI())
    game.printInstructions()
    game.runGameLoop()

    # sleep for 30 seconds before exiting
    time.sleep(1000 * 30)
    sys.exit()
def game_from_GUI():
    GameGUI().mainloop()
Beispiel #7
0
def load_board():       #refrences the GUI of connect 4, however it also refereces the loading method. This is to load the game into the GUI.
        b_gui = GameGUI()
        b_gui.load = True;
        b_gui.intialise_dynamic()
        gui = b_gui
Beispiel #8
0
def plays():    # the play method which is is called by the game_menu
        
        b_gui = GameGUI()               # assign the class of the standard Connect 4 game GUI to variable b_gui (creates new instance of class)  
        b_gui.intialise_dynamic()       # creating a method reference to the creation of the Connect 4 Grid GUI
        gui = b_gui                     # assigning the variable to the file
Beispiel #9
0
from level_data import levels
from gui import GameGUI
pygame.init()

# Initialize Game Screen
screen = pygame.display.set_mode((640, 480))
logo_img = pygame.image.load('Assets/Player_1.png')
logo_sprite = pygame.transform.scale(logo_img, (32, 32))
pygame.display.set_icon(logo_sprite)
pygame.display.set_caption('Invasion Force')

# Create Game Instance
current_game = game.Game(screen)
current_game.create_game()

game_gui = GameGUI(screen)

print(len(levels))

# Game Loop
while current_game.running:
    game_gui.score_text = game_gui.font.render(f"Score: {current_game.score}",
                                               True, (255, 255, 255))
    game_gui.level_text = game_gui.font.render(
        f"Level: {current_game.current_level + 1}", True, (255, 255, 255))
    try:
        game_gui.wave_text = game_gui.font.render(
            f"Wave: {current_game.game_levels[current_game.current_level].current_wave}",
            True, (255, 255, 255))
    except IndexError:
        pass