Esempio n. 1
0
 def match(self, player1_index: int, player2_index: int):
     score = [0, 0]
     player1 = self.participants[player1_index]
     player2 = self.participants[player2_index]
     for turn in range(self.repeat):
         g = Game(player1, player2, self.map_generator())
         winner = g.run()
         if winner == 0 or winner == 1:
             score[winner] += 1
             if score[winner] > self.repeat // 2 + 1:
                 break
     #while score[0] == score[1]:
     return (player1_index,
             player2_index) if score[0] > score[1] else (player2_index,
                                                         player1_index)
Esempio n. 2
0
def Match(player1: Player, player2: Player):
    cnt = [0, 0]
    for i in range(1):
        # dg = DesignGenerator(bridge=0.8, branch=(2, 4), depth=3)
        g = Game(player1.name, player2.name, Generate_Hexagon(4, 0.20, 0.20))

        f**k = g.run()
        if f**k==0:
            cnt[0] += 1
        elif f**k==1:
            cnt[1] += 1

    if cnt[0]>cnt[1]:
        player1.win(player2)
        player2.lose(player1)
    elif cnt[0]<cnt[1]:
        player2.win(player1)
        player1.lose(player2)
    else:
        player1.draw(player2)
        player2.draw(player1)
Esempio n. 3
0
 def __init__(self):
     self.cycle = Game()
Esempio n. 4
0
class Controller:
    def __init__(self):
        self.cycle = Game()

    def start(self):
        name = None
        self.cycle.load_data()
        while True:
            line = input()

            if line.startswith('/newchar')\
                    and len(line.split()) == 2:
                x = line.split()
                self.cycle.register(x[1])

            elif line.startswith('/newchar')\
                    and len(line.split()) != 2:
                print("Usage: /newchar <name of your new character>")

            elif line.startswith("/fight")\
                    and len(line.split()) == 3:
                x = line.split()
                self.cycle.fight(x[1], x[2])

            elif line.startswith('/fight')\
                    and len(line.split()) != 3:
                print(
                    "Usage: /fight <name of first warrior> <name of second warrior>"
                )

            elif line.startswith('/endgame'):
                break

            elif line.startswith('/login')\
                    and len(line.split()) == 2:
                x = line.split()
                if self.cycle.log_in(x[1]):
                    name = x[1]

            elif line.startswith('/login')\
                    and len(line.split()) != 2:
                print("Usage: /login <name of your character>")

            elif line.startswith('/forge')\
                    and len(line.split()) > 4:
                x = line.split()
                self.cycle.forge(x[1], x[2], x[3], x[4])

            elif line.startswith('/forge')\
                    and len(line.split()) < 4:
                print("Usage: /forge <bonus> <level> <type>")

            elif line.startswith('/find')\
                    and len(line.split()) == 2:
                x = line.split()
                self.cycle.ask_trade(self.cycle.weapon_list[x[1]])

            elif line.startswith('/info'):
                print(self.cycle.hero.call_info())

            elif line.startswith('/quest')\
                    and len(line.split()) == 2:
                x = line.split()
                if x[1] in self.cycle.quests.keys():
                    self.cycle.start_quest(x[1])

            elif line.startswith('/quest_list'):
                for i in self.cycle.quests.keys():
                    print(self.cycle.quests[i].call_info())

        if name:
            self.cycle.character_namespace[name] = self.cycle.hero
            print("Saved Successfully")
        self.cycle.save_data()
Esempio n. 5
0
from GameCore import Game
from MapDesign import g_design

MAX_TIME = 999999
MAX_TURN = 100
cnt = [0, 0]
##  very important:
#   测试时输入的样例规定:
#    1 2 30
#    1 3 40
#    qaq
#    返回:[(1,2,30.0),(1,3,40.0)]

if __name__ == '__main__':
    for i in range(100):
        g = Game('player1', 'player2', MAX_TIME, MAX_TURN, g_design)

        f**k = g.run()
        if f**k == "player1":
            cnt[0] += 1
        elif f**k == "player2":
            cnt[1] += 1
        print("now", cnt[0], cnt[1])
    print(cnt)

    # print(f"{g.run()} wins!")

    # 导出地图,给可视化
    with open("output.json", "w") as _f:
        json.dump(g.get_history(), _f)
Esempio n. 6
0
import json

from GameCore import Game
from MapDesign import g_design
from DesignGenerator import DesignGenerator
from HexagonForce import Generate_Hexagon

cnt = [0, 0]

if __name__ == '__main__':
    for i in range(1):
        # dg = DesignGenerator(bridge=0.8, branch=(2, 4), depth=3)
        g = Game('XHZAI一代', 'player2', Generate_Hexagon(4, 0.20, 0.20))

        f**k = g.run()
        if f**k == 0:
            cnt[0] += 1
        elif f**k == 1:
            cnt[1] += 1
            # 导出地图,给可视化
            with open("output_lose.json", "w") as _f:
                json.dump(g.get_history(), _f)
        print("now", cnt[0], cnt[1])
        print(g.get_history()["result"])
    print(cnt)

    # print(f"{g.run()} wins!")

    # 导出地图,给可视化
    with open("output.json", "w") as _f:
        json.dump(g.get_history(), _f)
import json

from GameCore import Game
from MapDesign import g_design
from DesignGenerator import DesignGenerator
from HexagonForce import Generate_Hexagon

cnt = [0, 0]

if __name__ == '__main__':
    for i in range(10):
        # dg = DesignGenerator(bridge=0.8, branch=(2, 4), depth=3)
        g = Game('player1_调参1', 'player1_调参2', Generate_Hexagon(4, 0.20, 0.20))

        f**k = g.run()
        if f**k == 0:
            cnt[0] += 1
        elif f**k == 1:
            cnt[1] += 1
            # 导出地图,给可视化
            with open("output_lose.json", "w") as _f:
                json.dump(g.get_history(), _f)
        print("now", cnt[0], cnt[1])
    print(cnt)

    # print(f"{g.run()} wins!")

    # 导出地图,给可视化
    with open("output.json", "w") as _f:
        json.dump(g.get_history(), _f)