Example #1
0
def do_turn(): #bot throws the dice, chooses what unit to move and does so	
	if game.memo.rolls == 0:#cant do a turn anymore anyway
		next_pl()
		return
	player = game.memo.act_pl

	if not game.rules.chessmod
		game.throw_the_dice("bot")
		if game.memo.may_spawn:
			possibs =game.memo.act_pl.units
			for i in [3,2,1,0]:
				if possibs[i].cond != 0:
					possibs.remove(i)
			selection = possibs[random.randint(0,len(possibs)-1)]
			game.actio([3],game.memo.act_pl,selection)
			return
		else:
			#ordinary turn
			selection = find_smartest(player,game.memo.dice)[0:2]
			game.actio([selection[1],game.memo.dice], player, selection[0])
			return

	else:
		selection = find_smartest_chess(player)[0:2]
		game.throw_the_dice(selection[1])
		game.actio([selection[1],game.memo.dice],player,selection[0])
		return
Example #2
0
    def networkPoll(self):
        data = network.getInput()
        for e in data:
            a = e[0]  # adress
            e = e[1]  # message
            # print e
            if e[0] == "g":  # gamestart
                game_start("lan", self.pl)
            elif e[0] == "d":
                if network.hosting:
                    network.send(e, a, True)
                game.throw_the_dice("butter", inp=int(e[1]))
            elif e[0] == "z":
                if network.hosting:
                    print("MUHAHAHA")  # this is called repeatedly
                    network.send(e, a, True)
                game.actio(int(e[2]), None, int(e[1]), fr=True)  # actio(doing,player,unit)
            elif e[0] == "o":  # optionsaenderung #TODO might not work, hasnt been tested
                if e[1] == "c":  # change chessmod
                    self.optwindow.chessmod.set_active(int(e[1]))
                    # self.optwindow.chessmod.toggled()
                elif e[1] == "j":  # change jumps
                    self.optwindow.check_jumps.set_active(int(e[1]))  # TODO geht nicht, und nur host darf das aendern
                else:
                    continue
            elif e[0] == "s":  # spieleraenderung
                try:
                    num = int(e[1])  # which player
                except:
                    continue
                if e[2] == "n":  # name
                    self.names[num].set_text(e[3:])
                elif e[2] == "c":  # controlled how
                    t = {"h": 0, "n": 3, "b": 2, "c": 1}[e[3]]
                    self.sel_but[num].set_active(t)
                else:
                    continue
            elif e[0] == "e":  # end of turn
                if network.hosting:  # send it to everyone else
                    network.send("e", adress=a, n=True)
                game.next_pl("nw")

            else:  # nix
                continue
        return 1