原子比例游戏


21

您的任务是使机器人扮演得分最高的Atomas

游戏的运作方式:

游戏板以6个“原子”的环开头,数字范围为13。您可以“玩”两个原子之间或另一个原子上的原子,具体取决于原子本身。

您可以有一个普通原子,也可以有一个特殊原子。

正常原子:

您可以在板上任意两个可用原子之间播放普通原子。

您从处于该范围内的原子开始1 to 3,但是该范围每40移动一次就增加1(因此,在40移动之后,范围变为2 to 4)。

如果板上的原子小于该范围,则有1 / no. of atoms of that number on the board可能产生。

假设您有一个2要玩的地方,董事会看起来像这样:

   1 1 2 1

让我们将放在的2右侧1

董事会现在变成:

   1 1 2 1 2

注意:木板环绕,所以1最左侧的实际上2是最右侧的旁边。稍后将很重要。

有“特殊”原子的4种类型,它们是:

+原子:

这个原子在两个原子之间起作用。它有五分之一的机会产卵。

如果原子两侧的+原子相同,则会发生聚变。运作方式如下:

The two atoms fuse together to create an atom one higher.
(So, two 3 atoms fuse together to form one 4 atom.)
While the atoms on both sides of the fused atom are equal:
    If the atoms on the side >= the fused atom:
        The new fused atom = the old fused atom's value + 2.
    If the atoms on the side < the fused atom:
        The new fused atom = the old fused atom's value + 1.

例:

   1 1 3 2 2 3  (the 1 on the left-hand side "wraps back" 
                 to the 3 on the right-hand side)

Let's use the + on the two 2's in the middle.

-> 1 1 3 3 3    (the two 2's fused together to make a 3)
-> 1 1 5        (the two 3's fused with the 3, and because 3 >= 3,
                 the new fused atom = 3 + 2 = 5)
-> 6            (the two 1's fused with the 5, since the board wraps,
                 and because 1 < 5, the new fused atom = 5 + 1 = 6)

Because the atoms on the sides of the 6 don't exist, fusion stops,
and the board is now [6].

如果原子两边的+原子都不相同,则+撑杆将停留在板上。

例:

   1 3 2 3 1 1

Let's use the + on the 2 and 3 in the middle.

-> 1 3 2 + 3 1 1 (2 != 3, so the + stays on the board)

-原子:

这个原子在另一个原子上播放。它产生的几率为十分之一。

-原子除去从基板的原子,以及让你选择要么:

  • 下一轮播放移除的原子,或者
  • 将其变成+原子以进行下一轮比赛。

例:

   1 3 2 3 1 1

Let's use the - on the left-hand 2.

-> 1 3 3 1 1    (the 2 is now removed from the board)

Let's turn it into a +, and place it in between the 3's.

-> 1 4 1 1      (the two 3's fused together to make a 4)
-> 5 1          (the two 1's fused with the 4, and because 1 < 4,
                 the new fused atom = 4 + 1 = 5)

+原子(B):

该原子在2个原子之间起作用。它的产生几率是80分之一,只有当得分> 750时才产生。

该原子与原子基本相同+,除了它将任意两个原子(甚至是)融合在一起+。从那时起,它遵循+规则(仅当融合原子两侧的原子相等时才将原子融合在一起)。

黑色导致的熔融原子+等于:

  • 聚变中较高原子数+ 3
  • 4如果两个稠合的原子是+

例:

   1 3 2 1 3 1

Let's use the black + on the 2 and 1 in the middle.

-> 1 3 5 3 1    (the 2 and 1 fused together to make a 2 + 3 = 5)
-> 1 6 1        (+ rule)
-> 7            (+ rule)

另一个例子:

   2 + + 2

Let's use the black + on the two +'s.

-> 2 4 2        (the two +'s fused together to make a 4)
-> 5            (+ rule)

克隆原子(C):

这个原子在另一个原子上播放。它产生的几率为60分之一,只有当得分> 1500时才产生。

克隆原子允许您选择一个原子,然后在下一轮播放它。

例:

   1 1 2 1

Let's use the clone on the 2, and place it to the right of the 1.

-> 1 1 2 1 2

这是我用Python 2构建的游戏:

import random
import subprocess

logs='atoms.log'
atom_range = [1, 3]
board = []
score = 0
move_number = 0
carry_over = " "
previous_moves = []

specials = ["+", "-", "B", "C"]


def plus_process(user_input):
    global board, score, previous_moves, matches
    previous_moves = []
    matches = 0

    def score_calc(atom):
        global score, matches
        if matches == 0:
            score += int(round((1.5 * atom) + 1.25, 0))
        else:
            if atom < final_atom:
                outer = final_atom - 1
            else:
                outer = atom
            score += ((-final_atom + outer + 3) * matches) - final_atom + (3 * outer) + 3
        matches += 1

    if len(board) < 1 or user_input == "":
        board.append("+")
        return None
    board_start = board[:int(user_input) + 1]
    board_end = board[int(user_input) + 1:]
    final_atom = 0
    while len(board_start) > 0 and len(board_end) > 0:
        if board_start[-1] == board_end[0] and board_end[0] != "+":
            if final_atom == 0:
                final_atom = board_end[0] + 1
            elif board_end[0] >= final_atom:
                final_atom += 2
            else:
                final_atom += 1
            score_calc(board_end[0])
            board_start = board_start[:-1]
            board_end = board_end[1:]
        else:
            break
    if len(board_start) == 0:
        while len(board_end) > 1:
            if board_end[0] == board_end[-1] and board_end[0] != "+":
                if final_atom == 0:
                    final_atom = board_end[0]
                elif board_end[0] >= final_atom:
                    final_atom += 2
                else:
                    final_atom += 1
                score_calc(board_end[0])
                board_end = board_end[1:-1]
            else:
                break
    if len(board_end) == 0:
        while len(board_start) > 1:
            if board_start[0] == board_start[-1] and board_start[0] != "+":
                if board_start[0] >= final_atom:
                    final_atom += 2
                else:
                    final_atom += 1
                score_calc(board_start[0])
                board_start = board_start[1:-1]
            else:
                break
    if matches == 0:
        board = board_start + ["+"] + board_end
    else:
        board = board_start + [final_atom] + board_end
        for a in range(len(board) - 1):
            if board[a] == "+":
                if board[(a + 1) % len(board)] == board[a - 1]:
                    board = board[:a - 1] + board[a:]
                    plus_process(a)
                    break


def minus_process(user_input, minus_check):
    global carry_over, board
    carry_atom = board[int(user_input)]
    if user_input == len(board) - 1:
        board = board[:-1]
    else:
        board = board[:int(user_input)] + board[int(user_input) + 1:]
    if minus_check == "y":
        carry_over = "+"
    elif minus_check == "n":
        carry_over = str(carry_atom)


def black_plus_process(user_input):
    global board
    if board[int(user_input)] == "+":
        if board[int(user_input) + 1] == "+":
            inter_atom = 4
        else:
            inter_atom = board[int(user_input) + 1] + 2
    else:
        if board[int(user_input)] + 1 == "+":
            inter_atom = board[int(user_input)] + 2
        else:
            inter_list = [board[int(user_input)], board[int(user_input) + 1]]
            inter_atom = (inter_list.sort())[1] + 2
    board = board[int(user_input) - 1:] + [inter_atom] * 2 + board[int(user_input) + 1:]
    plus_process(int(user_input) - 1)


def clone_process(user_input):
    global carry_over
    carry_over = str(board[int(user_input)])


def regular_process(atom,user_input):
    global board
    if user_input == "":
        board.append(random.randint(atom_range[0], atom_range[1]))
    else:
        board = board[:int(user_input) + 1] + [int(atom)] + board[int(user_input) + 1:]

def gen_specials():
    special = random.randint(1, 240)
    if special <= 48:
        return "+"
    elif special <= 60 and len(board) > 0:
        return "-"
    elif special <= 64 and len(board) > 0 and score >= 750:
        return "B"
    elif special <= 67 and len(board) > 0 and score >= 1500:
        return "C"
    else:
        small_atoms = []
        for atom in board:
            if atom not in specials and atom < atom_range[0]:
                small_atoms.append(atom)
        small_atom_check = random.randint(1, len(board))
        if small_atom_check <= len(small_atoms):
            return str(small_atoms[small_atom_check - 1])
        else:
            return str(random.randint(atom_range[0], atom_range[1]))


def specials_call(atom, user_input):
    specials_dict = {
        "+": plus_process,
        "-": minus_process,
        "B": black_plus_process,
        "C": clone_process
    }
    if atom in specials_dict.keys():
        if atom == "-":
            minus_process(user_input[0], user_input[1])
        else:
            specials_dict[atom](user_input[0])
    else:
        regular_process(atom,user_input[0])


def init():
    global board, score, move_number, carry_over, previous_moves
    board = []
    score = 0

    for _ in range(6):
        board.append(random.randint(1, 3))

    while len(board) <= 18:
        move_number += 1
        if move_number % 40 == 0:
            atom_range[0] += 1
            atom_range[1] += 1
        if carry_over != " ":
            special_atom = carry_over
            carry_over = " "
        elif len(previous_moves) >= 5:
            special_atom = "+"
        else:
            special_atom = gen_specials()
        previous_moves.append(special_atom)
        bot_command = "python yourBot.py"
        bot = subprocess.Popen(bot_command.split(),
                               stdout = subprocess.PIPE,
                               stdin = subprocess.PIPE)
        to_send="/".join([
            # str(score),
            # str(move_number),
            str(special_atom),
            " ".join([str(x) for x in board])
        ])
        bot.stdin.write(to_send)
        with open(logs, 'a') as f:f.write(to_send+'\n')
        bot.stdin.close()
        all_user_input = bot.stdout.readline().strip("\n").split(" ")
        specials_call(special_atom, all_user_input)

    print("Game over! Your score is " + str(score))

if __name__ == "__main__":
    for a in range(20):
        with open(logs, 'a') as f:f.write('round '+str(a)+'-'*50+'\n')
        init()

机器人是如何工作的:

输入项

  • 您的机器人将获得2个输入:当前正在运行的原子以及棋盘的状态。
  • 原子将像这样:
    • +为了一个+原子
    • -为了一个-原子
    • B一个黑色+原子
    • C 克隆原子
    • {atom} 对于一个正常原子
  • 董事会的状态将如下所示:
    • atom 0 atom 1 atom 2... atom n,原子之间用空格隔开(atom n回退到atom 1,以模拟“环”游戏板)
  • 这两个将以分隔/

输入示例:

1/1 2 2 3   (the atom in play is 1, and the board is [1 2 2 3])
+/1         (the atom in play is +, and the board is [1] on its own)

输出量

  • 您将输出一个字符串,具体取决于播放中的原子是什么。

    • 如果该原子要在两个原子之间发挥作用:

      • 输出要在其中播放原子的间隙。间隙就像每个原子之间的间隙,如下所示:

        atom 0, GAP 0, atom 1, GAP 1, atom 2, GAP 2... atom n, GAP N
        

        gap n表示要放置之间的原子atom 1和原子n),所以输出2,如果你要玩的原子gap 2

    • 如果要在原子上播放原子:
      • 输出要在其上2播放的原子,因此如果要在上播放该原子atom 2
    • 如果原子是-
      • 输出要在其上播放原子的原子,然后输出一个空格,然后y/n选择将其转换为+稍后的原子,因此,2, "y"如果要在其上播放原子atom 2,则要将其转换为+注意:这需要2个输入,而不是1个。

输出示例:

(Atom in play is a +)
2   (you want to play the + in gap 2 - between atom 2 and 3)
(Atom in play is a -)
3 y  (you want to play the - on atom 3, and you want to change it to a +)
2 n  (you want to play the - on atom 2, and you don't want to change it)
  • 为了使机器人正常工作,您必须去Popen到位(在代码结尾处),并用使程序作为Pythonic列表运行的任何内容替换它(因此,如果您的程序是derp.java,请替换["python", "bot.py"]["java", "derp.java"])。

特定答案的规格:

  • 将您的机器人的整个代码放入答案中。如果不合适,则不计算在内。
  • 每个用户可以拥有1个以上的漫游器,但是,它们都应位于单独的答案中。
  • 另外,给您的机器人起个名字。

得分:

  • 得分最高的机器人将获胜。
    • 您的机器人程序将测试20场比赛,最终得分是20场比赛的平均值。
  • 决胜局将是答案上传的时间。
  • 因此,您的答案将采用以下格式:

    {language}, {bot name}
    Score: {score}
    

祝好运!


如何生成的+一个-原子的工作?如果您选择了,y您是否可以保证+下一步行动?
Ton Hospel '16

4
我建议更改您的机器人驱动程序,以便它可以处理任何在STDIN上输入并在STDOUT上给出结果的独立程序。这应该使语言具有独立性,并且本网站上使用的大多数语言都可以轻松地做到这一点。当然,这意味着要定义严格的I / O格式,例如input_atom\natom0 atom1 .... atomn\nSTDIN
Ton Hospel'Oct 11'16

1
该代码似乎可以放入+元素列表中,但是在文本描述中找不到该位置
Ton Hospel

1
嗯,我知道您使该程序能够调用外部机器人。但是,您还需要在STDIN上传递当前的移动编号和得分,否则该机器人无法预测每个原子在将来发生的机会
Ton Hospel

1
如果控制器没有得到改进,人们是否会花时间来创建解决方案,这很容易理解。我喜欢这个问题,但是不喜欢实现。
mbomb007 '16

Answers:


1

Python,draftBot,分数= 889

import random
def h(b):
    s=0
    for x in b:
        try:
            s+=int(x)
        except: 
            s+=0
    return s
def d(i):g=i.split("/");a=g[0];b=g[1].split(" ");return(a,b)
def p(a,_,j):
    v=[]
    for x in _:
        try:
            v.append(int(x))
        except: 
            v.append(0)
    try:
        v=v[:j+1]+[int(a)]+v[j+1:]
    except: 
        v=v[:j+1]+[a]+v[j+1:]
    r1=[[]];b=[x for x in v];m=range(len(b)+1)
    for k in m:
        for i in m:
            for j in range(i):
                c = b[j:i + 1]
                if len(c)%2==0 and c==c[::-1] and 0 not in c:r1.append(c)
        b.insert(0, b.pop())
    q1=max(r1,key=len)
    r2=[[]];b=[x for x in v];m=range(len(b)+1)
    for k in m:
        for i in m:
            for j in range(i):
                c = b[j:i + 1]
                if len(c)>2 and len(c)%2==1 and c==c[::-1] and "+" in c and 0 not in c:r2.append(c)
        b.insert(0, b.pop())
    q2=max(r2,key=h)
    with open('f.log', 'a') as f:f.write('pal '+str(_)+' : '+str(q1)+' : '+str(q2)+'\n')
    if q2!=[]:return 100+h(q2)
    else:return len(q1)
i=raw_input()
(a,b)=d(i)
if a in ['C','B']:print('0')
elif a=='-':print("0 y" if random.randint(0, 1) == 1 else "0 n")
else:q,j=max((p(a,b,j),j)for j in range(len(b)));print(str(j))

我发现控制器:

  • 当分数超过1500时崩溃;
  • 在相同情况下不能正确合并原子。

0

Python,RandomBot,分数= 7.95

没什么特别的,只是一个随机机器人。

import random

game_input = raw_input().split("/")
current_atom = game_input[0]
board = game_input[1].split(" ")

if current_atom != "-":
    print(random.randint(0, len(board) - 1))
else:
    random_choice = " y" if random.randint(0, 1) == 1 else " n"
    print(str(random.randint(0, len(board) - 1)) + random_choice)

0

Python,BadPlayer,分数= 21.45

import random

try:
    raw_input
except:
    raw_input = input

game_input = raw_input().split("/")
current_atom = game_input[0]
board = game_input[1].split(" ")

def get_chain(board, base):
    chain = []
    board = board[:]
    try:
        while board[base] == board[base + 1]:
            chain = [board[base]] + chain + [board[base + 1]]
            del board[base]
            del board[base]
            base -= 1
    except IndexError:
        pass
    return chain

def biggest_chain(board):
    chains = []
    base = 0
    i = 0
    while i < len(board) - 1:
        chains.append([i, get_chain(board, i)])
        i += 1
    return sorted(chains, key=lambda x: len(x[1]) / 2)[-1]

def not_in_chain():
    a, b = biggest_chain(board)
    if len(b) == 0:
        print(random.randint(0, len(board) - 1))
    elif random.randint(0, 1) == 0:
        print(random.randint(a + len(b)/2, len(board) - 1))
    else:
        try:
            print(random.randint(0, a - len(b)/2 - 1))
        except:
            print(random.randint(a + len(b)/2, len(board) - 1))

if current_atom in "+B":
    a, b = biggest_chain(board)
    if len(b) == 0:
        print(0)
    else:
        print(a)
elif current_atom == "C":
    not_in_chain()
elif current_atom == "-":
    a, b = biggest_chain(board)
    if len(b) == 0:
        print(str(random.randint(0, len(board) - 1)) + " n")
    elif random.randint(0, 1) == 0:
        print(str(random.randint(a + len(b)/2, len(board) - 1)) + " n")
    else:
        try:
            print(str(random.randint(0, a - len(b)/2 - 1)) + " n")
        except:
            print(str(random.randint(0, len(board) - 1)) + " n")
else:
    not_in_chain()

只是一个非常糟糕的机器人,经常使控制器崩溃


它如何使控制器崩溃?如果是的话,那就是控制器或您的机器人有问题吗?
mbomb007 '16

@ mbomb007我不记得为什么崩溃了,但是崩溃发生在控制器中
TuxCrafting

该机器人应该可以正常工作,没有任何错误,只需稍微修改一下代码即可适应更新的“ stdin”。
clismique '16
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.