Example #1
0
 def set_grid(self, newgrid=None):
     """ Sets player's grid from input, or empty(0) 10x10 grid [columns[rows]] if no input """
     if getattr(self, 'grid', 1) or newgrid == None:
         self.grid = Grid()
         co_ordiantes = []
         for row in range(10):
             for column in range(10):
                 co_ordiantes.append([row, column])
         self.grid.set_value(newgrid)
Example #2
0
    def adapter(self):
        # l = LedRenderer(15, 20)
        data = []
        for i in range(0, 15):
            for j in range(0, 20):
                data.append(self.grid[i][j])

        r = TextRenderer(15, 20)
        g = Grid(r.width, r.height, r)
        g.render(data)
Example #3
0
def HighVar(ModelList, GridSize, Pro, path, l_rate):
    TrapReward = None
    NonReward = [-12, 10]
    Trans = Grid(GridSize)
    Ground(ModelList, GridSize, Pro, path, Trans, TrapReward, NonReward,
           l_rate)
Example #4
0
class Player(object):
    """ Player Object """
    """ Design note: I'm begingin to think that Grid should be a seperate class,
	However unsure whether each player would have one grid or two.
	One makes more sense as each player 'owns' just their grid, but then
	grid would need a "print_tracking_grid" method to print the opponents grid
	with all the information except hits and misses hidden. Which is easy, but is that the best design? """
    """ All returning functions must first return a list with any display lines to be edited. Even if this list is empty.	"""

    #These are NOT class variables so they don't go here
    #grid = []
    #score = 0
    #ships = []

    def __init__(self, player_number=1, player_name="Test"):
        """ Initialization """
        #Instance variables should be created here
        #self.input = Input() #Fix this later.
        self.set_grid()
        self.set_score()
        self.set_number(player_number)
        self.set_name(player_name)
        self.ship_status = {}  #Dictionary of Ships

    def set_grid(self, newgrid=None):
        """ Sets player's grid from input, or empty(0) 10x10 grid [columns[rows]] if no input """
        if getattr(self, 'grid', 1) or newgrid == None:
            self.grid = Grid()
            co_ordiantes = []
            for row in range(10):
                for column in range(10):
                    co_ordiantes.append([row, column])
            self.grid.set_value(newgrid)

    def get_grid(self):
        """ Since Python has no private varibles this is just fluff """
        return [], self.grid

    def set_score(self, score=0):
        """ Unessasary in Python. Score defaults to 0 """
        self.score = score

    def get_score(self):
        """ Unessasary in Python. """
        return [], self.score

    def set_number(self, player_number):
        """ Unessasary in Python. """
        self.number = player_number

    def get_number(self):
        """ Unessasary in Python. """
        return [], self.number

    def set_name(self, player_name):
        """ Unessasary in Python. """
        self.name = player_name  #Comment During Testing

    def get_name(self):
        """ Unessasary in Python. """
        return [], self.name

    def place_ship(self, ship, co_ords, orientation):
        """ Attempts to place a ship on the player's grid. """
        try:
            self.ship_status(ship)
            return [[10], ["Ship Already Placed!!"]], False
        except KeyError:
            try:
                self.check_ship_placement(
                    Ship_Size(ship).value, co_ords, orientation)
                # return [range(10),self.print_grid(range(10))],True ##  Need to work out now how to call print_grid muliple times and output to list, without a for loop.
                return [], True
            except PlacementOutsideGrid:
                return [[10], ["Ship Placement Falls Outside Grid"]], False
            except ShipsOverlap:
                return [[10], ["Ship Placement Overlaps Annother Ship"]], False
            except:
                print("How did we get here?")
                return [], False
        except:
            print("How did we get here?")
            return [], False

    def check_ship_placement(self, size, co_ords, orientation):
        if orientation == 'v':
            if (co_ords[1] + size) < 9:
                for square in range(size):
                    if self.grid[co_ords[0]][co_ords[1] + square] != 0:
                        pass
                    else:
                        elf.grid[co_ords[0]][co_ords[1] +
                                             square] == Ship_Type(ship).value
            elif orientation == 'h':
                for square in range(Ship_Size(ship).value):
                    self.grid[co_ords[0] +
                              square][co_ords[1]] == Ship_Type(ship).value
            for square in range(size):
                if self.grid[co_ords[0]][co_ords[1] + square] != 0:
                    return [], False
        elif orientation == 'h' and (co_ords[0] + size) < 9:
            for square in range(size):
                if self.grid[co_ords[0]][co_ords[1]] != 0:
                    return [], False
        else:
            return [], True

    def check_co_ordinates(co_ordinates):
        """ Check string 'co-ordinates' to ensure they are value. Returns bool . Update: This should happen in Grid"""
        good_co_ordinates = False
        #print("Check Starts False")
        for letter in 'ABCDEFGHIJ':
            if letter == co_ordinates[0]:
                #print("Letter was good")
                good_co_ordinates = True
                break
            elif letter == co_ordinates[0].upper():
                print("Letter must be Uppercase")
        for number in '0123456789':
            if number == co_ordinates[1]:
                #print("Number was good")
                good_co_ordinates = (True and good_co_ordinates)
                break
        return good_co_ordinates

    def update_grid(self, co_ordinates):
        """ Updates the Grid for a single square. Returns the value that WAS there, or -1 if space has been attacked """
        space = self.grid[Column[co_ordinates[0]].value][co_ordinates[1]]
        if space == 0:
            #Miss
            self.grid[Column[co_ordinates[0]].value][co_ordinates[1]] = 11
        elif space == 11 or space == 10:
            #These are bad co-ordinates. They have already been attacked.
            space = -1
        else:
            #Hit
            self.grid[Column[co_ordinates[0]].value][co_ordinates[1]] = 10
        return space

    """ Design Question. Should Player or Game class we be responisble for "attacks"? """

    def attack(self, player):  #NEED TO TEST
        """ Uses Input() to get co-ords to attack, updates the grid of the targeted 'player', then returns a string describing the result. """
        while True:
            #co_ordinates = self.input.co_ordinates()
            #space = player.update_grid(co_ordinates)
            space = 0
            if space < 0:
                print("You've already attacked there!")
            else:
                if space == 0:
                    return "MISS"
                else:
                    return "You Hit"
Example #5
0
        return "Patrol Boat"
    elif flag == Ship_Type.D.value:
        return "Destroyer"
    elif flag == Ship_Type.S.value:
        return "Submarine"
    elif flag == Ship_Type.B.value:
        return "Battleship"
    elif flag == Ship_Type.C.value:
        return "Aircraft Carrier"
    else:
        return "Error invalid ship flag"


if __name__ == "__main__":
    TestInterface = Interface()
    Testgrid = Grid()
    print(Testgrid)

    #test_grid = [[0,0,0,0,0,0,0,1,1,0],[0,2,0,0,0,0,0,0,0,3],[0,2,0,0,0,0,0,0,0,3],[0,2,0,0,4,0,0,0,0,3],[0,0,0,0,4,0,0,0,0,0],[0,0,0,0,4,0,0,0,0,0],[0,0,0,0,4,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,5,5,5,5,5,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
    #Display = Console_Display()
    #Display.update_grids(['Test'],0,TestGrid)

    #game = Game()
    #game.run()
    #game.display()

    #Andrew = Player()
    #Andrew.set_grid(test_grid)
    #New_input = Input()
    #print (New_input.attack())
    #print (New_input.player_name())
Example #6
0
from TextRenderer import TextRenderer
from Grids import Grid
import pygame
from Ressource import Ressource


r = TextRenderer(15, 20)
g = Grid(r.width, r.height, r)
ressource = Ressource()

pygame.init()
pygame.display.set_mode((100, 100))
pygame.joystick.init()


g.render(ressource.startbild)
ressource.start()
ressource.color_game()


#dino_jump()
#render_play()
#g.render(ressource.play)

running = True

while running:
    running_game = False
    for i in pygame.event.get():
        if i.type == pygame.QUIT:
            running = False
                          dual=False,
                          max_iter=10000,
                          fit_intercept=False,
                          tol=10**-4,
                          verbose=True))]

pipe1 = imbPipeline(
    estimators1
)  # Use of imbPipeline makes possible the implementation of SMOTE techniques
pipe2 = imbPipeline(estimators2)
pipe3 = imbPipeline(estimators3)
pipe4 = imbPipeline(estimators4)
pipe5 = imbPipeline(estimators5)

param_grid1 = dict(
    clf__n_neighbors=Grid.KNN()['n_neighbors'],
    clf__p=Grid.KNN()['p'],
    clf__weights=Grid.KNN()
    ['weights'])  #Parameters are gathered from a user-defined class.
param_grid2 = dict(clf__C=Grid.LR()['C'], clf__penalty=Grid.LR()['penalty'])
param_grid3 = dict(clf__alpha=Grid.NN()['alpha'],
                   clf__activation=Grid.NN()['activation'])
param_grid4 = dict(clf__n_estimators=Grid.RF()['n_estimators'],
                   clf__max_depth=Grid.RF()['max_depth'],
                   clf__min_samples_split=Grid.RF()['min_samples_split'],
                   clf__min_samples_leaf=Grid.RF()['min_samples_leaf'])
param_grid5 = dict(clf__C=Grid.SVM()['C'], clf__penalty=Grid.SVM()['penalty'])

grid1 = model_selection.GridSearchCV(pipe1,
                                     param_grid=param_grid1,
                                     cv=cv,
Example #8
0
class Ressource:
    r = TextRenderer(15, 20)
    g = Grid(r.width, r.height, r)

    startbild = [[1, 17, 0, 0], [2, 17, 0, 0], [3, 17, 0, 0], [4, 17, 0, 0],
                 [1, 16, 0, 0], [1, 15, 0, 0], [2, 15, 0, 0], [3, 15, 0, 0],
                 [4, 16, 0, 0], [4, 15, 0, 0], [1, 13, 0, 0], [2, 13, 0, 0],
                 [3, 13, 0, 0], [4, 13, 0, 0], [1, 11, 0, 0], [2, 11, 0, 0],
                 [3, 11, 0, 0], [4, 11, 0, 0], [1, 10, 0, 0], [1, 9, 0, 0],
                 [2, 9, 0, 0], [3, 9, 0, 0], [4, 9, 0, 0], [1, 7, 0, 0],
                 [2, 7, 0, 0], [3, 7, 0, 0], [4, 7, 0, 0], [1, 6, 0, 0],
                 [4, 6, 0, 0], [1, 5, 0, 0], [2, 5, 0, 0], [3, 5, 0, 0],
                 [4, 5, 0, 0], [7, 17, 0, 0], [7, 16, 0, 0], [7, 15, 0, 0],
                 [8, 15, 0, 0], [9, 15, 0, 0], [10, 15, 0, 0], [11, 17, 0, 0],
                 [11, 16, 0, 0], [11, 15, 0, 0], [10, 17, 0, 0], [7, 13, 0, 0],
                 [8, 13, 0, 0], [9, 13, 0, 0], [10, 13, 0, 0], [11, 13, 0, 0],
                 [11, 12, 0, 0], [11, 11, 0, 0], [10, 11, 0, 0], [9, 11, 0, 0],
                 [8, 11, 0, 0], [7, 11, 0, 0], [7, 9, 0, 0], [8, 9, 0, 0],
                 [9, 9, 0, 0], [10, 9, 0, 0], [11, 9, 0, 0], [7, 8, 0, 0],
                 [7, 7, 0, 0], [8, 7, 0, 0], [9, 7, 0, 0], [7, 6, 0, 0],
                 [7, 5, 0, 0], [8, 5, 0, 0], [9, 5, 0, 0], [10, 5, 0, 0],
                 [11, 5, 0, 0], [7, 3, 0, 0], [8, 3, 0, 0], [9, 3, 0, 0],
                 [9, 3, 0, 0], [11, 3, 0, 0], [7, 2, 0, 0], [7, 1, 0, 0],
                 [8, 1, 0, 0], [9, 1, 0, 0], [9, 2, 0, 0], [10, 3, 0, 0],
                 [5, 2, 5, 0], [4, 2, 5, 0], [4, 3, 5, 0], [3, 2, 5, 0],
                 [2, 2, 5, 0], [2, 1, 5, 0]]

    play = [[11, 18, 1, 0], [10, 18, 1, 0], [9, 18, 1, 0], [8, 18, 1, 0],
            [7, 18, 1, 0], [6, 18, 1, 0], [5, 18, 1, 0], [4, 18, 1, 0],
            [4, 17, 1, 0], [4, 16, 1, 0], [4, 15, 1, 0], [4, 14, 1, 0],
            [4, 13, 1, 0], [4, 12, 1, 0], [4, 11, 1, 0], [4, 10, 1, 0],
            [4, 9, 1, 0], [4, 8, 1, 0], [4, 7, 1, 0], [4, 6, 1,
                                                       0], [4, 5, 1, 0],
            [4, 4, 1, 0], [4, 3, 1, 0], [4, 2, 1, 0], [4, 1, 1,
                                                       0], [5, 1, 1, 0],
            [6, 1, 1, 0], [7, 1, 1, 0], [8, 1, 1, 0], [9, 1, 1, 0],
            [10, 1, 1, 0], [11, 1, 1, 0], [11, 2, 1, 0], [11, 3, 1, 0],
            [11, 4, 1, 0], [11, 5, 1, 0], [11, 6, 1, 0], [11, 7, 1, 0],
            [11, 8, 1, 0], [11, 9, 1, 0], [11, 10, 1, 0], [11, 11, 1, 0],
            [11, 12, 1, 0], [11, 13, 1, 0], [11, 13, 1, 0], [11, 14, 1, 0],
            [11, 15, 1, 0], [11, 16, 1, 0], [11, 17, 1, 0], [3, 16, 0, 0],
            [2, 16, 0, 0], [2, 17, 0, 0], [1, 16, 0, 0], [1, 15, 0, 0],
            [3, 11, 0, 0], [2, 11, 0, 0], [2, 12, 0, 0], [1, 11, 0, 0],
            [1, 10, 0, 0], [6, 16, 0, 0], [6, 15, 0, 0], [6, 14, 0, 0],
            [7, 14, 0, 0], [8, 14, 0, 0], [8, 15, 0, 0], [8, 16, 0, 0],
            [7, 16, 0, 0], [9, 16, 0, 0], [6, 12, 0, 0], [7, 12, 0, 0],
            [8, 12, 0, 0], [9, 12, 0, 0], [9, 11, 0, 0], [6, 9, 0, 0],
            [7, 9, 0, 0], [8, 9, 0, 0], [9, 9, 0, 0], [6, 8, 0,
                                                       0], [6, 7, 0, 0],
            [7, 7, 0, 0], [8, 7, 0, 0], [9, 7, 0, 0], [8, 8, 0,
                                                       0], [6, 5, 0, 0],
            [7, 5, 0, 0], [8, 5, 0, 0], [9, 4, 0, 0], [8, 4, 0,
                                                       0], [6, 3, 0, 0],
            [7, 3, 0, 0], [8, 3, 0, 0], [3, 5, 0, 0], [2, 5, 0, 0],
            [2, 6, 0, 0], [1, 4, 0, 0], [1, 5, 0, 0]]

    def start(self):
        play = self.play
        for i in range(0, len(play)):
            if play[i][0] == 1 or play[i][0] == 2 or play[i][0] == 3:
                play[i][2] = 5
        for i in range(0, len(play)):
            if play[i][2] == 1:
                play[i][2] = 0

    def color_game(self):
        time.sleep(0.5)
        c = [1, 1, 6]
        for k in range(2):
            for i in range(0, len(self.startbild)):
                if (self.startbild[i][0] == 4 or self.startbild[i][0]
                        == 11) and self.startbild[i][2] == 0:
                    self.startbild[i][2] = random.choice(c)
                    self.g.render(self.startbild)
                    time.sleep(0.05)

    def getBush(self):
        return [[12, 0, 5, 0], [11, 1, 5, 0], [10, 1, 5, 0]]

    def getBird(self):
        return [[9, 0, 2, 0], [9, 0, 2, 0], [9, 0, 7, 0]]

    def generateDino(self):
        dino = [[[0, 1, 0, 0], [0, 1, 0, 0], [0, 0, 7, 0]],
                [[0, 1, 7, 0], [0, 1, 0, 0], [0, 0, 7, 0]],
                [[0, 0, 7, 0], [0, 1, 0, 0], [0, 1, 0, 0]],
                [[0, 0, 7, 0], [0, 1, 0, 0], [0, 0, 7, 0]]]
        # print(dino)
        return dino

    def generateDuckedDino(self):
        duckedDino = [[[0, 0, 7, 0], [0, 0, 7, 0], [0, 0, 7, 0]],
                      [[0, 0, 7, 0], [0, 0, 7, 0], [0, 0, 7, 0]],
                      [[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]],
                      [[0, 0, 7, 0], [0, 1, 0, 0], [0, 0, 7, 0]]]
        return duckedDino