Esempio n. 1
0
def checkEndTurn(s):
    """
    Fonction permettant de checker si le joueur à encore des point d'action (aprés une action). Met fin au tour automatiquement et retourne false.
    :param s: retour du String
    :return: Boolean (Le tour à été terminée?)
    """

    if "point d'action" in s:  # Si on n'as plus de PA
        print("END TUNRNN ")
        client.send("ENDTURN")
        print("DDD1", client.receive())
        print("DDD2", client.receive())
        return True
    return False
Esempio n. 2
0
def getDeliveries():
    """
    Fonction permettant d'obtenir une liste de dictionnaires correspondant au livraisons à effectuer

    acces => resultat[arrayIndex]["code"]
    :return: list of DICT
    """
    client.send("GETDELIVERIES")
    str = client.receive()
    deliveries = str.split("|")
    deliveries.pop(0)
    res = []
    for deliverie in deliveries:
        args = deliverie.split(";")
        res.append({
            "code": int(args[0]),
            "valeur": args[1],
            "cooYRestaurant": int(args[2]),
            "cooXRestaurant": int(args[3]),
            "cooYMaison": int(args[4]),
            "cooXMaison": int(args[5]),
            "tourLimit": int(args[6].replace("\r\n", ""))
        })

    return res
Esempio n. 3
0
def StepFollowPath(BikerNum, EndX, EndY, matrice, OurNum):
    """
    Fonction permettant de faire aller le coursier "BikerNum" une pas vers le point (EndX, EndY)
    :param BikerNum: Numéro du biken Integer
    :param EndX: Integer
    :param EndY: Integer
    :return: Boolean (Le tour à été terminée?)
    """

    # Lazyness /20
    MoveDef = dict()
    MoveDef[0] = dict()
    MoveDef[1] = dict()
    MoveDef[-1] = dict()

    MoveDef[1][0] = "T"
    MoveDef[-1][0] = "B"
    MoveDef[0][1] = "L"
    MoveDef[0][-1] = "R"

    Biker = getBikers(OurNum)[BikerNum]
    path, _ = getPath(Biker["x"], Biker["y"], EndX, EndY, matrice)
    if len(path) <= 1:
        print("[WARN] Next move: 0, 0")
        return "d"
    nextmove = (path[0][0] - path[1][0], path[0][1] - path[1][1])
    movestr = MoveDef[nextmove[1]][nextmove[0]]

    client.send("MOVE|" + str(BikerNum) + "|" + movestr)
    s = client.receive()
    return checkEndTurn(s)
Esempio n. 4
0
def getBikers(num):
    """
    Fonction permettant d'obtenir une liste de dictionnaires correspondant aux livreurs
    :param num: Team Integer
    :return: list of DICT
    """
    client.send("GETBIKERS|" + str(num))
    dstr = client.receive()
    bikers = dstr.split("|")
    bikers.pop(0)
    res = []
    for biker in bikers:
        args = biker.split(";")
        res.append({"numero": args[0], "y": int(args[1]), "x": int(args[2])})
    return res
Esempio n. 5
0
    def receiveMsg(self):
        while True:
            msg = client.receive()

            if msg == 0:
                self.output.text += "SERVER CONNECTION CLOSED"
                self.delLines()

                #stop user from sending messages
                self.input.text = ""
                self.input.disabled = True
                return

            if not isinstance(msg, str):
                if msg.content == DISCONNECT_MESSAGE:
                    return

                self.output.text += emoji.emojize(
                    f"[color={msg.user.colour}]{msg.user.name}[/color]: {msg.content}\n",
                    use_aliases=True)
                self.delLines()
Esempio n. 6
0
#!/usr/bin/env python3
import client
import time

client.connect("127.0.0.1", 8080)

client.send(
    "Client"
)  # The unique ID will be implemented. This is just so we can quickly test this now

client.send("Hello")
print(client.receive())

client.send("How are you")
print(client.receive())

client.send("That's good")
print(client.receive())
Esempio n. 7
0
def giveLivraison(biker_num, liv_code):
    client.send("DELIVER|" + str(biker_num) + "|" + str(liv_code))
    return not checkEndTurn(client.receive())
Esempio n. 8
0
def takeLivraison(biker_num, liv_code):
    client.send("TAKE|" + str(biker_num) + "|" + str(liv_code))
    return not checkEndTurn(client.receive())
Esempio n. 9
0
 def receive_message(self, instance):
     message = client.receive()
     if message != None:
         self.textBox.text += message + "\n"
Esempio n. 10
0
n.mainloop()

m = tkinter.Tk()
mm = tkinter.Frame(m)

mm.pack()

m.title('Best chat in the neighborhood')
# Set a fixed size for the Chat window SO YOU WONT F**K IT UP
m.geometry("450x270")

chat = tkinter.Text(mm, width=48, height=10, bg="LightBlue3")
chat.configure(state="disabled")
send_bt = tkinter.Button(m, text='Send', height=1, width=15, command=lambda: client.send(client_message_box, m))
scroll_bar = tkinter.Scrollbar(mm, orient="vertical")
scroll_bar.config(command=chat.yview)
client_message_box = tkinter.Text(m, width=50, height=3)

chat.pack(side="left", fill="y")
scroll_bar.pack(side="right", fill="y")
client_message_box.pack()
send_bt.pack()

receive_thread = Thread(target=lambda: client.receive(chat))
receive_thread.start()

m.protocol("WM_DELETE_WINDOW", lambda: client.on_closing(m))

m.mainloop()
Esempio n. 11
0
            if input() == "r":
                print("taking my turn")
                rolls = die.get_rolls()
                pickled = pickle_turn(HOST_ID, rolls)

        host.broadcast(pickled)
        player_id, rolls = unpickle_turn(pickled)
        players[player_id].play(rolls)
        b.display()
        player_id = (player_id + 1) % PLAYER_COUNT

elif inp == "client":

    client = client.Client()
    client.connect(ip, port)
    CLIENT_ID = int(client.receive())
    PLAYER_COUNT = int(client.receive())
    b = player.Board(PLAYER_COUNT)
    players = [player.Player(b, i) for i in range(PLAYER_COUNT)]
    die = player.Die()

    player_id = 0
    while True:
        if player_id == CLIENT_ID:  #if its their turn
            if input() == "r":
                print("taking my turn")
                rolls = die.get_rolls()
                pickled = pickle_turn(CLIENT_ID, rolls)
                client.send(pickled)
        else:  #if they receive someone else's turn from the server
            pickled = client.receive()
Esempio n. 12
0
def p_send(p):
    """send : SEND"""
    server.send(conn)
    client.receive(client_socket)
Esempio n. 13
0
import client
import funcs
import re

if __name__ == "__main__":

    ### INIT
    client.send("pylong")
    StartMsg = client.receive()
    OurNum = (re.findall(r'\d+', StartMsg))[0]

    client.send("GETMAP")
    _rawMap = client.receive()
    _rawMatrice = funcs.getmatrice(_rawMap)
    matrice = funcs.creatematrice(_rawMatrice)

    savedliv = []
    bl = dict()
    task = [0, 0]
    gotfood = [False, False]
    bikersData = funcs.getBikers(OurNum)
    delivriesData = funcs.getDeliveries() + savedliv

    while True:
        Biker = bikersData[0]
        if task[0] == 0:
            task[0] = funcs.bestDelivery(
                delivriesData, matrice, OurNum, 0, bl
            )["code"]  #funcs.Bestdelivery(0, matrice, savedliv, OurNum)["livraison"]["code"]

        cur = funcs.getLivraisonByCode(task[0], savedliv, OurNum)