Example #1
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
Example #2
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 #3
0
	def click(self,button,cond, pos):
		if memo.wait:
			return

		if game.memo.selection != 4:#unit selected?
			#TODO einheiten selektion ueberschreiben muss angepasst werden
			u = game.memo.selection
			doing = [0,0]
			pf = u.move(game.memo.dice,True)
			pb = u.move(game.memo.dice,False)
			#valid order?
			#doing[0] =
			if cond == u.cond and pos == u.pos:#clicked himself
				if game.memo.may_spawn:#may spawn
					doing[0] = 3
					doing.pop(-1)
				elif game.memo.suicide:#has_to_die
					doing[0] = 4
					doing.pop(-1)
				else:#fail
					game.select_unit(4)
					self.note.set_text("\nInvalid Command\n")
					return
				result = game.actio(doing, game.memo.act_pl,u)
				game.select_unit(4)
				return
			#valid order?
			#move forward
			elif pf != False and pos == pf[0] and cond == pf[1]:
				doing[0] = 1
			#move backward
			elif pb != False and pos == pb[0] and cond == pb[1]:
				doing[0] = 2 
			#move forth over corner
			elif pf != False and pf[0] in [4,14,24,34] and pf[0]%20 == pos%20:#expecting jump over corner
				doing[0] = 1
			#move back over corner
			elif pf != False and pb[0] in [4,14,24,34] and pb[0]%20 == pos%20:#expecting jump over corner
				doing[0] = 2
			#version 2.5
			elif (game.memo.may_spawn and 
			pos == game.memo.act_pl.nr*10 and cond == 1 and
			u.cond == 0):#spawn by spawnpointclick
				doing[0] = 3
				doing.pop(-1)
				result = game.actio(doing, game.memo.act_pl,u)
				game.select_unit(4)
				return
			elif (game.memo.suicide and cond == 0 and
				u.cond != 0):#suicide by graveclick
				doing[0] = 4
				doing.pop(-1)
				result = game.actio(doing, game.memo.act_pl,u)
				game.select_unit(4)
				return

			else:#no valid order
				self.note.set_text("\nInvalid Command\n")
				game.select_unit(4)
				return
		else:
			#select
			game.select_unit(game.get_unit_bypos(pos,cond))
			return

		doing[1] = game.memo.dice
		if doing[1] == 0:
			self.note.set_text(game.memo.act_pl.name+"\n("+game.memo.act_pl.get_color()+")Please throw \n the dice first!")

		game.actio(doing, game.memo.act_pl,game.memo.selection)
		game.memo.selection = 4