Пример #1
0
    def __init__(self):
        self.grid = Grid(10, 10)

        #Arrow key bot
        self.bot = Bot(AQUA)
        self.bot.put(self.grid, Cell(5, 6))

        self.chaser = Chaser(self.bot)
        self.chaser.put(self.grid, Cell(0, 0))

        self.create_walls()
Пример #2
0
    def __init__(self):
        self.grid = Grid(10, 10)

        #Arrow key bot
        self.bot1 = Bot(AQUA)
        self.bot1.put(self.grid, Cell(3, 3))

        #WASD key bot
        self.bot2 = Bot(ORANGE)
        self.bot2.put(self.grid, Cell(5, 5))

        #Automatic bot
        self.autobot = AutoBot()
        self.autobot.put(self.grid, Cell(0, 0))
Пример #3
0
    def __init__(self):
        self.grid = Grid(10, 10)

        #Arrow key bot
        self.bot1 = Bot(AQUA)
        self.bot1.put(self.grid, Cell(3, 3))

        #WASD key bot
        self.bot2 = Bot(ORANGE)
        self.bot2.put(self.grid, Cell(5, 5))

        #Automatic bot
        self.autobot = AutoBot()
        self.autobot.put(self.grid, Cell(0, 0))
Пример #4
0
 def create_bots(self, *args):
     if not self.bots:
         self.bots = [
             Bot(
                 new=True,
                 coords=self.get_coords(*args)
             ) for _ in range(COUNT_BOTS)
         ]
Пример #5
0
def handle_bot_moved_head(bots_list):
    maxx, maxy = 0, 0
    all_bots.clear()
    oled_display.clear()
    bots_in_display = 0
    for bot_json in bots_list:
        b = Bot(bot_json, oled_display)
        if b.on_display():
            bots_in_display += 1
        #print("bot created ", b)
        all_bots.append(b)
        b.draw()

        maxx, maxy = max(maxx, b.pos[0]), max(maxy, b.pos[1])

    oled_display.update()
    time.sleep(SLEEP_AFTER_UPDATE)
    print("#" + str(num_msgs), "botscount", len(bots_list), "on_display",
          bots_in_display, "maxxy", round(maxx, 2), round(maxy, 2))
Пример #6
0
    def __init__(self):
        self.grid = Grid(10, 10)

        #Arrow key bot
        self.bot = Bot(AQUA)
        self.bot.put(self.grid, Cell(5, 6))
        
        self.chaser = Chaser(self.bot)
        self.chaser.put(self.grid, Cell(0, 0))
        
        self.create_walls()
Пример #7
0
class Example2(SketchMode):
    SCALE = 40

    ARROW_MAP = {UP: 'north', DOWN: 'south', LEFT: 'west', RIGHT: 'east'}

    def __init__(self):
        self.grid = Grid(10, 10)

        #Arrow key bot
        self.bot = Bot(AQUA)
        self.bot.put(self.grid, Cell(5, 6))

        self.chaser = Chaser(self.bot)
        self.chaser.put(self.grid, Cell(0, 0))

        self.create_walls()

    def create_walls(self):
        self.walls = []
        invalid_locations = [self.bot.cell, self.chaser.cell]
        for x in xrange(20):
            row = randint(0, 9)
            col = randint(0, 9)
            cell = Cell(row, col)
            if cell not in invalid_locations:
                wall = Wall()
                wall.put(self.grid, cell)
                self.walls.append(wall)

    def update(self):
        if frameCount % 30 == 0:
            self.chaser.act()

    def draw(self):
        background(0)

        #Make a 2-cell margin
        translate(self.SCALE * 3, self.SCALE * 3)
        #Scale the grid to be the desired size
        scale(self.SCALE)
        #strokeWeight should not vary with the scale
        strokeWeight(1.0 / self.SCALE)

        self.grid.draw()
        for wall in self.walls:
            wall.draw()
        self.bot.draw()
        self.chaser.draw()

    def keyReleased(self):
        if key == CODED and keyCode in self.ARROW_MAP:
            try:
                self.bot.move_dir(self.ARROW_MAP[keyCode])
            except ValueError as e:
                print e

    def __str__(self):
        return "Example 2: Chaser"
Пример #8
0
#Torus duel test

import random
from bots import Bot
from group import Group

#creating 2 bots

bot1 = Bot('Bob', 20, 20, 10, 2, 60, 5, 40, 3, 25, 2, 3)
bot2 = Bot('Bill', 20, 20, 10, 2, 60, 5, 40, 3, 25, 2, 3)

#let's fight melee!

while True:
	
        bot1_ini = bot1.initiative_roll()
        bot2_ini = bot2.initiative_roll()

        if bot1_ini > bot2_ini:
                print(bot1.name+' act first')
                if bot1.melee_hit(bot2):
                        bot2.take_damage(bot1.melee_dmg)
                        if bot2.hp <= 0:
                                break
                if bot2.melee_hit(bot1):
                        bot1.take_damage(bot2.melee_dmg)
                        if bot1.hp <= 0:
                                break
        elif bot2_ini > bot1_ini:
                print(bot2.name+' act first')
                if bot2.melee_hit(bot1):
Пример #9
0
class Example1(SketchMode):
    SCALE = 40

    ARROW_MAP = {UP: 'north', DOWN: 'south', LEFT: 'west', RIGHT: 'east'}

    WASD_MAP = {'w': 'north', 's': 'south', 'a': 'west', 'd': 'east'}

    def __init__(self):
        self.grid = Grid(10, 10)

        #Arrow key bot
        self.bot1 = Bot(AQUA)
        self.bot1.put(self.grid, Cell(3, 3))

        #WASD key bot
        self.bot2 = Bot(ORANGE)
        self.bot2.put(self.grid, Cell(5, 5))

        #Automatic bot
        self.autobot = AutoBot()
        self.autobot.put(self.grid, Cell(0, 0))

    def update(self):
        if frameCount % 30 == 0:
            self.autobot.act()

    def draw(self):
        background(0)

        #Make a 2-cell margin
        translate(self.SCALE * 3, self.SCALE * 3)
        #Scale the grid to be the desired size
        scale(self.SCALE)
        #strokeWeight should not vary with the scale
        strokeWeight(1.0 / self.SCALE)

        self.grid.draw()
        self.bot1.draw()
        self.bot2.draw()
        self.autobot.draw()

    def keyReleased(self):
        if key == CODED and keyCode in self.ARROW_MAP:
            try:
                self.bot1.move_dir(self.ARROW_MAP[keyCode])
            except ValueError as e:
                print e
        elif key in self.WASD_MAP:
            try:
                self.bot2.move_dir(self.WASD_MAP[key])
            except ValueError as e:
                print e

    def __str__(self):
        return "Example 1: Basic Entities"
Пример #10
0
#Torus

import random
from bots import Bot
from group import Group

#creating 6 bots

bot1 = Bot('Bob', 20, 20, 10, 2, 60, 5, 40, 3, 25)
bot2 = Bot('Bill', 20, 20, 10, 2, 60, 5, 40, 3, 25)
bot3 = Bot('Raoul', 20, 20, 10, 2, 60, 5, 40, 3, 25) 
bot4 = Bot('Dan', 20, 20, 10, 2, 60, 5, 40, 3, 25)
bot5 = Bot('Ray', 20, 20, 10, 2, 60, 5, 40, 3, 25)
bot6 = Bot('Moh', 20, 20, 10, 2, 60, 5, 40, 3, 25)

#creating 2 groups

group1 = Group("Alpha")
group2 = Group("Omega")

print()
group1.add_bot(bot1)
group1.add_bot(bot2)
group1.add_bot(bot3)

print()
group2.add_bot(bot4)
group2.add_bot(bot5)
group2.add_bot(bot6)

print()
Пример #11
0
#Torus

import random
from bots import Bot
from group import Group

#creating 6 bots

bot1 = Bot('Bob', 20, 20, 10, 2, 60, 5, 40, 3, 25, 2, 3)
bot2 = Bot('Bill', 20, 20, 10, 2, 60, 5, 40, 3, 25, 2, 3)
bot3 = Bot('Raoul', 20, 20, 10, 2, 60, 5, 40, 3, 25 2, 3) 
bot4 = Bot('Dan', 20, 20, 10, 2, 60, 5, 40, 3, 25 2, 3)
bot5 = Bot('Ray', 20, 20, 10, 2, 60, 5, 40, 3, 25 2, 3)
bot6 = Bot('Moh', 20, 20, 10, 2, 60, 5, 40, 3, 25 2, 3)

#creating 2 groups

group1 = Group("Alpha")
group2 = Group("Omega")

print()
group1.add_bot(bot1)
group1.add_bot(bot2)
group1.add_bot(bot3)

print()
group2.add_bot(bot4)
group2.add_bot(bot5)
group2.add_bot(bot6)

print()
Пример #12
0
class Example1(SketchMode):
    SCALE = 40
    
    ARROW_MAP = {
        UP: 'north',
        DOWN: 'south',
        LEFT: 'west',
        RIGHT: 'east'
    }

    WASD_MAP = {
        'w': 'north',
        's': 'south',
        'a': 'west',
        'd': 'east'
    }
    def __init__(self):
        self.grid = Grid(10, 10)

        #Arrow key bot
        self.bot1 = Bot(AQUA)
        self.bot1.put(self.grid, Cell(3, 3))

        #WASD key bot
        self.bot2 = Bot(ORANGE)
        self.bot2.put(self.grid, Cell(5, 5))

        #Automatic bot
        self.autobot = AutoBot()
        self.autobot.put(self.grid, Cell(0, 0))

    def update(self):
        if frameCount % 30 == 0:
            self.autobot.act()

    def draw(self):
        background(0)

        #Make a 2-cell margin
        translate(self.SCALE * 3, self.SCALE * 3)
        #Scale the grid to be the desired size
        scale(self.SCALE)
        #strokeWeight should not vary with the scale
        strokeWeight(1.0 / self.SCALE)

        self.grid.draw()
        self.bot1.draw()
        self.bot2.draw()
        self.autobot.draw()
    
    def keyReleased(self):
        if key == CODED and keyCode in self.ARROW_MAP:
            try:
                self.bot1.move_dir(self.ARROW_MAP[keyCode])
            except ValueError as e:
                print e
        elif key in self.WASD_MAP:
            try:
                self.bot2.move_dir(self.WASD_MAP[key])
            except ValueError as e:
                print e
        
    def __str__(self):
        return "Example 1: Basic Entities"
Пример #13
0
import logging
from bots import Bot

logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S',
                    filename="sample.log")
logger = logging.getLogger("TeleBot")
logger.setLevel(level=logging.INFO)

if __name__ == '__main__':
    bot = Bot(logger)
    bot.start()
Пример #14
0
    def init_game(self, n_players, base_money, sb=25, bb=50, simulation=False):
        self._update_key = True
        if simulation == True:
            self.players = [
                Player(i + 1, base_money, bot=Bot("Random"))
                for i in range(n_players - 1)
            ] + [Player(n_players, base_money)]
        else:
            self.players = [
                Player(i + 1, base_money) for i in range(n_players)
            ]
        self.board = Board(sb, bb, self.players)
        self.deck = Deck()
        self.all_in = False

        self.game_menu = tk.Frame(self.root,
                                  bg='#3545B0')  #bg same as self.background
        self.game_menu.rowconfigure(0, weight=15)
        self.game_menu.columnconfigure(0, weight=15)

        self.button_panel = tk.Frame(self.game_menu, bg='#3C4163')
        self.button_panel.grid(row=0, column=1)
        self.button_panel.rowconfigure(0, weight=1)

        self.init_button = tk.Button(self.button_panel,
                                     text='Play',
                                     command=lambda: self.main(simulation))
        self.init_button.grid(row=0, column=0, padx=10, pady=10)

        self.cards_button = tk.Button(self.button_panel,
                                      text='Give cards',
                                      command=self.set_cards)
        self.cards_button.grid(row=0, column=1, padx=10, pady=10)

        self.background = tk.Canvas(self.game_menu,
                                    width=WIDTH,
                                    height=HEIGHT,
                                    bd=0,
                                    highlightthickness=0,
                                    relief='ridge',
                                    bg='#3545B0')  #bg='#4459E3'
        self.background.grid(row=1, column=1, padx=0, pady=0)

        self.background.create_oval(WIDTH / 32 * 6,
                                    HEIGHT / 18 * 5.3,
                                    WIDTH / 32 * 26,
                                    HEIGHT / 18 * 12.8,
                                    fill='#333333')
        self.background.create_oval(WIDTH / 32 * 6.5,
                                    HEIGHT / 18 * 5.7,
                                    WIDTH / 32 * 25.5,
                                    HEIGHT / 18 * 12.3,
                                    fill='#80522F')
        self.background.create_oval(WIDTH / 32 * 7.5,
                                    HEIGHT / 18 * 6.6,
                                    WIDTH / 32 * 24.5,
                                    HEIGHT / 18 * 11.4,
                                    fill='#2D9F01')

        angle = 360 / n_players
        for i, x in enumerate(self.players):
            coord_x = ((((WIDTH / 32 * 26) -
                         (WIDTH / 32 * 6)) / 2) + WIDTH / 32 * 2) * math.cos(
                             math.radians(i * angle)) + WIDTH / 2
            coord_y = ((
                ((HEIGHT / 18 * 12.8) -
                 (HEIGHT / 18 * 5.3)) / 2) + HEIGHT / 18 * 2) * math.sin(
                     math.radians(i * angle)) + HEIGHT / 2
            bet_x = ((((WIDTH / 32 * 26) -
                       (WIDTH / 32 * 6)) / 2) - WIDTH / 32 * 2) * math.cos(
                           math.radians(i * angle)) + WIDTH / 2
            bet_y = ((((HEIGHT / 18 * 12.8) -
                       (HEIGHT / 18 * 5.3)) / 2) - HEIGHT / 18 * 2) * math.sin(
                           math.radians(i * angle)) + HEIGHT / 2

            x.player_active = self.background.create_rectangle(
                coord_x - WIDTH / 32 * 1,
                coord_y - HEIGHT / 18 * 1,
                coord_x + WIDTH / 32 * 1,
                coord_y + HEIGHT / 18 * 1,
                fill='#FFFFFF',
            )
            x.player_name = self.background.create_text(coord_x,
                                                        coord_y,
                                                        text=f'{x.id}')
            x.player_money = self.background.create_text(coord_x,
                                                         coord_y +
                                                         HEIGHT / 18 * 0.5,
                                                         text=f"{x.money} $")
            x.player_hand = self.background.create_text(coord_x,
                                                        coord_y +
                                                        HEIGHT / 18 * 1.5,
                                                        text=f"{x.hand}")
            x.player_button = self.background.create_oval(
                coord_x - WIDTH / 32 * 1.25,
                coord_y + HEIGHT / 18 * 0.75,
                coord_x - WIDTH / 32 * 0.75,
                coord_y + HEIGHT / 18 * 1.25,
                fill='',
                width=0)
            x.player_button_name = self.background.create_text(
                coord_x - WIDTH / 32 * 1, coord_y + HEIGHT / 18 * 1, text='')
            x.player_action = self.background.create_text(
                coord_x,
                coord_y - HEIGHT / 18 * 1.5,
                text=f'{x.last_move}',
                fill='YELLOW',
                font=(None, 10, 'bold'))
            x.player_bet = self.background.create_text(bet_x,
                                                       bet_y,
                                                       text=f"{x.current_bet}")

        self.community_board = self.background.create_rectangle(
            WIDTH / 32 * 14,
            HEIGHT / 18 * 6.5,
            WIDTH / 32 * 18,
            HEIGHT / 18 * 8,
            fill='#FFFFFF')
        self.current_step = self.background.create_text(WIDTH / 32 * 16,
                                                        HEIGHT / 18 * 6,
                                                        text="",
                                                        fill='#31DEDE',
                                                        font=(None, 15,
                                                              'bold'))
        self.community_cards = self.background.create_text(
            WIDTH / 32 * 16,
            HEIGHT / 18 * 9,
            text=f"{self.board.community_cards}")
        self.pot = self.background.create_text(
            WIDTH / 32 * 16,
            HEIGHT / 18 * 7.25,
            text=
            f"{[x.id for x in self.board.active_pot['player_list']]}\n{self.board.active_pot['value']}"
        )

        self.below_background = tk.Frame(self.game_menu)
        self.below_background.grid(row=2,
                                   column=1,
                                   sticky='s',
                                   padx=10,
                                   pady=20)

        self.pots = tk.Canvas(self.below_background,
                              width=WIDTH / 2,
                              height=HEIGHT / 18,
                              bd=0,
                              highlightthickness=0,
                              relief='ridge',
                              bg='#85503C')
        #for i in self.board.pots:
        #    self.pots.create_text(WIDTH/2,HEIGHT/2,text=f"{i['player_list']}\n{i['value']}")
        self.pots.grid()

        self.left_background = tk.Frame(self.game_menu,
                                        bg='BLACK',
                                        width=WIDTH / 32 * 8,
                                        height=HEIGHT / 18 * 12)
        self.left_background.grid_propagate(0)
        self.left_background.grid(row=1,
                                  column=0,
                                  sticky='w',
                                  padx=10,
                                  pady=20)

        self.historic = tk.Text(self.left_background,
                                fg='#00FF00',
                                bg='BLACK',
                                height=int(math.floor(
                                    (HEIGHT / 18 * 12) / 16)),
                                bd=0,
                                relief='ridge',
                                highlightthickness=0,
                                width=int(WIDTH / 32 * 8))
        self.historic.config(state='disabled')
        self._log_message('Creating the board', False)
        self._log_message(
            f'Settings : Players = {n_players} ; Money = {base_money} ; Simulation = {simulation}',
            False)
        self.historic.grid(row=1, column=0, sticky='n')
Пример #15
0
from bots import Bot
from field import Field

fieldX = 2000
fieldY = 2000
frames = 1000

botnum = 500

treenum = 60
bspawn = 0.3
tradius = 100

field = Field(fieldX, fieldY, treenum, bspawn, tradius)

botlist = [Bot(field) for i in range(botnum)]

xs = [0] * frames
ys = [0] * frames
ths = [0] * frames

bxs = [0] * frames
bys = [0] * frames

for i in range(frames):
    print(i + 1)

    field.update()

    bs = []
    for tree in field.trees:
Пример #16
0
class Example2(SketchMode):
    SCALE = 40
    
    ARROW_MAP = {
        UP: 'north',
        DOWN: 'south',
        LEFT: 'west',
        RIGHT: 'east'
    }
    
    def __init__(self):
        self.grid = Grid(10, 10)

        #Arrow key bot
        self.bot = Bot(AQUA)
        self.bot.put(self.grid, Cell(5, 6))
        
        self.chaser = Chaser(self.bot)
        self.chaser.put(self.grid, Cell(0, 0))
        
        self.create_walls()
    
    def create_walls(self):
        self.walls = []
        invalid_locations = [self.bot.cell, self.chaser.cell]
        for x in xrange(20):
            row = randint(0, 9)
            col = randint(0, 9)
            cell = Cell(row, col)
            if cell not in invalid_locations:
                wall = Wall()
                wall.put(self.grid, cell)
                self.walls.append(wall)
        

    def update(self):
        if frameCount % 30 == 0:
            self.chaser.act()

    def draw(self):
        background(0)

        #Make a 2-cell margin
        translate(self.SCALE * 3, self.SCALE * 3)
        #Scale the grid to be the desired size
        scale(self.SCALE)
        #strokeWeight should not vary with the scale
        strokeWeight(1.0 / self.SCALE)

        self.grid.draw()
        for wall in self.walls:
            wall.draw()
        self.bot.draw()
        self.chaser.draw()
    
    def keyReleased(self):
        if key == CODED and keyCode in self.ARROW_MAP:
            try:
                self.bot.move_dir(self.ARROW_MAP[keyCode])
            except ValueError as e:
                print e
    
    def __str__(self):
        return "Example 2: Chaser"