Ai 创想家 迷宫寻宝 最强代码(针对小学组的信息素养大赛)

接下来,我们开门见山,先揭露代码!!!

import api

history = []

multi = 1.25

midfield_addition = 3

sidefield_addition = 1.5

midfield = [(1,7),(2,7),(7,1),(7,2),(7,12),(7,13),(12,7),(13,7),

(3,3),(3,4),(3,5),(3,6),(3,7),(3,8),(3,9),(3,10),(3,11),

(4,3),(4,4),(4,5),(4,9),(4,10),(4,11),

(5,3),(5,4),(5,5),(5,6),(5,7),(5,8),(5,9),(5,10),(5,11),

(6,3),(6,5),(6,9),(6,11),

(7,3),(7,5),(7,9),(7,11),

(8,3),(8,5),(8,9),(8,11),

(9,3),(9,4),(9,5),(9,6),(9,7),(9,8),(9,9),(9,10),(9,11),

(10,3),(10,4),(10,5),(10,9),(10,10),(10,11),

(11,3),(11,4),(11,5),(11,6),(11,7),(11,8),(11,9),(11,10),(11,11),

]

sidefield = [(1,4),(1,5),(1,6),(1,8),(1,9),(1,10),

(4,1),(5,1),(6,1),(8,1),(9,1),(10,1),

(4,13),(5,13),(6,13),(8,13),(9,13),(10,13),

(13,4),(13,5),(13,6),(13,8),(13,9),(13,10),

]

def should_leave():

    e_row = api.get.exit(what="row")

    e_col = api.get.exit(what="col")

    path_len = api.check.path_len(row=e_row, col=e_col)

    my_energy = api.get.my(what="energy")

    if my_energy <= path_len + 1:

        return True

    else:

        return False

def get_update_value(item,dis,item_row,item_col):

    if item == "red_gem":

        value = 6

        value = value / (dis+1)

        if closer(item_row,item_col) == False:

            value = value / 100

        return value

    elif item == "yellow_gem":

        value = 1

        value = value / (dis+1)

        if closer(item_row,item_col) == False:

            value = value / 100

        return value

def closer(item_row,item_col):

    player = api.check.who_is_closer(row=item_row, col=item_col)

    me_closer = player.id == api.get.my("id")

    return me_closer

def update(context):

    my_row = api.get.my('row')

    my_col = api.get.my('col')

    enemy_row = api.get.enemy('row')

    enemy_col = api.get.enemy('col')

    up_row = my_row - 1

    up_col = my_col

    down_row = my_row + 1

    down_col = my_col

    left_row = my_row

    left_col = my_col - 1

    right_row = my_row

    right_col = my_col + 1

    yellow0_row = api.get.item(name="yellow_gem", n=0, what="row")

    yellow0_col = api.get.item(name="yellow_gem", n=0, what="col")

    yellow1_row = api.get.item(name="yellow_gem", n=1, what="row")

    yellow1_col = api.get.item(name="yellow_gem", n=1, what="col")

    yellow2_row = api.get.item(name="yellow_gem", n=2, what="row")

    yellow2_col = api.get.item(name="yellow_gem", n=2, what="col")

    yellow3_row = api.get.item(name="yellow_gem", n=3, what="row")

    yellow3_col = api.get.item(name="yellow_gem", n=3, what="col")

    red0_row = api.get.item(name="red_gem", n=0, what="row")

    red0_col = api.get.item(name="red_gem", n=0, what="col")

    red1_row = api.get.item(name="red_gem", n=1, what="row")

    red1_col = api.get.item(name="red_gem", n=1, what="col")

    up_score = 0

    down_score = 0

    left_score = 0

    right_score = 0

    maze = context.maze

    maze[yellow0_row][yellow0_col] = "yellow0_gem"

    maze[yellow1_row][yellow1_col] = "yellow1_gem"

    maze[yellow2_row][yellow2_col] = "yellow2_gem"

    maze[yellow3_row][yellow3_col] = "yellow3_gem"

    maze[red0_row][red0_col] = "red0_gem"

    maze[red1_row][red1_col] = "red1_gem"

    maze[my_row][my_col] = "me"

    maze[enemy_row][enemy_col] = "enemy"

    print("↑ 向上方向计算")

    if maze[up_row][up_col] == "WALL":

        up_score = 0

        print("道路不可通行","\n")

    else:

        yellow0_path = api.check.path(start=(up_row, up_col), end=(yellow0_row, yellow0_col))

        yellow1_path = api.check.path(start=(up_row, up_col), end=(yellow1_row, yellow1_col))

        yellow2_path = api.check.path(start=(up_row, up_col), end=(yellow2_row, yellow2_col))

        yellow3_path = api.check.path(start=(up_row, up_col), end=(yellow3_row, yellow3_col))

        red0_path = api.check.path(start=(up_row, up_col), end=(red0_row, red0_col))

        red1_path = api.check.path(start=(up_row, up_col), end=(red1_row, red1_col))

        yellow0_score = get_update_value("yellow_gem",len(yellow0_path),yellow0_row,yellow0_col)

        yellow1_score = get_update_value("yellow_gem",len(yellow1_path),yellow1_row,yellow1_col)

        yellow2_score = get_update_value("yellow_gem",len(yellow2_path),yellow2_row,yellow2_col)

        yellow3_score = get_update_value("yellow_gem",len(yellow3_path),yellow3_row,yellow3_col)

        red0_score = get_update_value("red_gem",len(red0_path),red0_row,red0_col)

        red1_score = get_update_value("red_gem",len(red1_path),red1_row,red1_col)

        up1_area = []

        if my_col == enemy_col:

            if my_row > enemy_row:

                for n in range(enemy_row+1,my_row):

                    up1_area.append(maze[n][my_col])

        if "yellow0_gem" in up1_area:

            yellow0_score = yellow0_score * multi

        if "yellow1_gem" in up1_area:

            yellow1_score = yellow1_score * multi

        if "yellow2_gem" in up1_area:

            yellow2_score = yellow2_score * multi

        if "yellow3_gem" in up1_area:

            yellow3_score = yellow3_score * multi

        if "red0_gem" in up1_area:

            red0_score = red0_score * multi

        if "red1_gem" in up1_area:

            red1_score = red1_score * multi

        up2_area = []

        if my_row < enemy_row:

            if my_col < enemy_col:

                for n in range(my_row,enemy_row+1):

                    for i in range(my_col,enemy_col+1):

                        up2_area.append(maze[n][i])

            elif my_col > enemy_col:

                for n in range(my_row,enemy_row+1):

                    for i in range(enemy_col,my_col+1):

                        up2_area.append(maze[n][i])

        elif my_row > enemy_row:

            if my_col < enemy_col:

                for n in range(enemy_row,my_row+1):

                    for i in range(my_col,enemy_col+1):

                        up2_area.append(maze[n][i])

            elif my_col > enemy_col:

                for n in range(enemy_row,my_row+1):

                    for i in range(enemy_col,my_col+1):

                        up2_area.append(maze[n][i])

        if "yellow0_gem" in up2_area:

            yellow0_score = yellow0_score * multi

        if "yellow1_gem" in up2_area:

            yellow1_score = yellow1_score * multi

        if "yellow2_gem" in up2_area:

            yellow2_score = yellow2_score * multi

        if "yellow3_gem" in up2_area:

            yellow3_score = yellow3_score * multi

        if "red0_gem" in up2_area:

            red0_score = red0_score * multi

        if "red1_gem" in up2_area:

            red1_score = red1_score * multi

        up3_area = []

        for (row,col) in midfield:

            up3_area.append(maze[row][col])

        if "yellow0_gem" in up3_area:

            yellow0_score = yellow0_score * midfield_addition

        if "yellow1_gem" in up3_area:

            yellow1_score = yellow1_score * midfield_addition

        if "yellow2_gem" in up3_area:

            yellow2_score = yellow2_score * midfield_addition

        if "yellow3_gem" in up3_area:

            yellow3_score = yellow3_score * midfield_addition

        if "red0_gem" in up3_area:

            red0_score = red0_score * midfield_addition

        if "red1_gem" in up3_area:

            red1_score = red1_score * midfield_addition

       

        up_lis = [yellow0_score,yellow1_score,yellow2_score,yellow3_score,red0_score,red1_score]

        best = max(up_lis)

        up_lis.remove(best)

        second_best = max(up_lis)

        up_score = best + second_best

        if context.round != 0:

            if history[len(history)-1] == "D":

                up_score = up_score * 0.95

        print(best,second_best)

        print("综合权重:", up_score,"\n")


 

    print("↓ 向下方向计算")

    if maze[down_row][down_col] == "WALL":

        down_score = 0

        print("道路不可通行","\n")

    else:

        yellow0_path = api.check.path(start=(down_row, down_col), end=(yellow0_row, yellow0_col))

        yellow1_path = api.check.path(start=(down_row, down_col), end=(yellow1_row, yellow1_col))

        yellow2_path = api.check.path(start=(down_row, down_col), end=(yellow2_row, yellow2_col))

        yellow3_path = api.check.path(start=(down_row, down_col), end=(yellow3_row, yellow3_col))

        red0_path = api.check.path(start=(down_row, down_col), end=(red0_row, red0_col))

        red1_path = api.check.path(start=(down_row, down_col), end=(red1_row, red1_col))

        yellow0_score = get_update_value("yellow_gem",len(yellow0_path),yellow0_row,yellow0_col)

        yellow1_score = get_update_value("yellow_gem",len(yellow1_path),yellow1_row,yellow1_col)

        yellow2_score = get_update_value("yellow_gem",len(yellow2_path),yellow2_row,yellow2_col)

        yellow3_score = get_update_value("yellow_gem",len(yellow3_path),yellow3_row,yellow3_col)

        red0_score = get_update_value("red_gem",len(red0_path),red0_row,red0_col)

        red1_score = get_update_value("red_gem",len(red1_path),red1_row,red1_col)

        down1_area = []

        if my_col == enemy_col:

            if my_row < enemy_row:

                for n in range(my_row+1,enemy_row):

                    down1_area.append(maze[n][my_col])

        if "yellow0_gem" in down1_area:

            yellow0_score = yellow0_score * multi

        if "yellow1_gem" in down1_area:

            yellow1_score = yellow1_score * multi

        if "yellow2_gem" in down1_area:

            yellow2_score = yellow2_score * multi

        if "yellow3_gem" in down1_area:

            yellow3_score = yellow3_score * multi

        if "red0_gem" in down1_area:

            red0_score = red0_score * multi

        if "red1_gem" in down1_area:

            red1_score = red1_score * multi

        down2_area = []

        if my_row < enemy_row:

            if my_col < enemy_col:

                for n in range(my_row,enemy_row+1):

                    for i in range(my_col,enemy_col+1):

                        down2_area.append(maze[n][i])

            elif my_col > enemy_col:

                for n in range(my_row,enemy_row+1):

                    for i in range(enemy_col,my_col+1):

                        down2_area.append(maze[n][i])

        elif my_row > enemy_row:

            if my_col < enemy_col:

                for n in range(enemy_row,my_row+1):

                    for i in range(my_col,enemy_col+1):

                        down2_area.append(maze[n][i])

            elif my_col > enemy_col:

                for n in range(enemy_row,my_row+1):

                    for i in range(enemy_col,my_col+1):

                        down2_area.append(maze[n][i])

        if "yellow0_gem" in down2_area:

            yellow0_score = yellow0_score * multi

        if "yellow1_gem" in down2_area:

            yellow1_score = yellow1_score * multi

        if "yellow2_gem" in down2_area:

            yellow2_score = yellow2_score * multi

        if "yellow3_gem" in down2_area:

            yellow3_score = yellow3_score * multi

        if "red0_gem" in down2_area:

            red0_score = red0_score * multi

        if "red1_gem" in down2_area:

            red1_score = red1_score * multi

        down3_area = []

        for (row,col) in midfield:

            down3_area.append(maze[row][col])

        if "yellow0_gem" in down3_area:

            yellow0_score = yellow0_score * midfield_addition

        if "yellow1_gem" in down3_area:

            yellow1_score = yellow1_score * midfield_addition

        if "yellow2_gem" in down3_area:

            yellow2_score = yellow2_score * midfield_addition

        if "yellow3_gem" in down3_area:

            yellow3_score = yellow3_score * midfield_addition

        if "red0_gem" in down3_area:

            red0_score = red0_score * midfield_addition

        if "red1_gem" in down3_area:

            red1_score = red1_score * midfield_addition

        down_lis = [yellow0_score,yellow1_score,yellow2_score,yellow3_score,red0_score,red1_score]

        best = max(down_lis)

        down_lis.remove(best)

        second_best = max(down_lis)

        down_score = best + second_best

        if context.round != 0:

            if history[len(history)-1] == "U":

                down_score = down_score * 0.95

        print(best,second_best)

        print("综合权重:", down_score)

    print("← 向左方向计算")

    if maze[left_row][left_col] == "WALL":

        left_score = 0

        print("道路不可通行","\n")

    else:

        yellow0_path = api.check.path(start=(left_row, left_col), end=(yellow0_row, yellow0_col))

        yellow1_path = api.check.path(start=(left_row, left_col), end=(yellow1_row, yellow1_col))

        yellow2_path = api.check.path(start=(left_row, left_col), end=(yellow2_row, yellow2_col))

        yellow3_path = api.check.path(start=(left_row, left_col), end=(yellow3_row, yellow3_col))

        red0_path = api.check.path(start=(left_row, left_col), end=(red0_row, red0_col))

        red1_path = api.check.path(start=(left_row, left_col), end=(red1_row, red1_col))

        yellow0_score = get_update_value("yellow_gem",len(yellow0_path),yellow0_row,yellow0_col)

        yellow1_score = get_update_value("yellow_gem",len(yellow1_path),yellow1_row,yellow1_col)

        yellow2_score = get_update_value("yellow_gem",len(yellow2_path),yellow2_row,yellow2_col)

        yellow3_score = get_update_value("yellow_gem",len(yellow3_path),yellow3_row,yellow3_col)

        red0_score = get_update_value("red_gem",len(red0_path),red0_row,red0_col)

        red1_score = get_update_value("red_gem",len(red1_path),red1_row,red1_col)

        left1_area = []

        if my_row == enemy_row:

            if my_col > enemy_col:

                for n in range(enemy_col+1,my_col):

                    left1_area.append(maze[my_row][n])

        if "yellow0_gem" in left1_area:

            yellow0_score = yellow0_score * multi

        if "yellow1_gem" in left1_area:

            yellow1_score = yellow1_score * multi

        if "yellow2_gem" in left1_area:

            yellow2_score = yellow2_score * multi

        if "yellow3_gem" in left1_area:

            yellow3_score = yellow3_score * multi

        if "red0_gem" in left1_area:

            red0_score = red0_score * multi

        if "red1_gem" in left1_area:

            red1_score = red1_score * multi

        left2_area = []

        if my_row < enemy_row:

            if my_col < enemy_col:

                for n in range(my_row,enemy_row+1):

                    for i in range(my_col,enemy_col+1):

                        left2_area.append(maze[n][i])

            elif my_col > enemy_col:

                for n in range(my_row,enemy_row+1):

                    for i in range(enemy_col,my_col+1):

                        left2_area.append(maze[n][i])

        elif my_row > enemy_row:

            if my_col < enemy_col:

                for n in range(enemy_row,my_row+1):

                    for i in range(my_col,enemy_col+1):

                        left2_area.append(maze[n][i])

            elif my_col > enemy_col:

                for n in range(enemy_row,my_row+1):

                    for i in range(enemy_col,my_col+1):

                        left2_area.append(maze[n][i])

        if "yellow0_gem" in left2_area:

            yellow0_score = yellow0_score * multi

        if "yellow1_gem" in left2_area:

            yellow1_score = yellow1_score * multi

        if "yellow2_gem" in left2_area:

            yellow2_score = yellow2_score * multi

        if "yellow3_gem" in left2_area:

            yellow3_score = yellow3_score * multi

        if "red0_gem" in left2_area:

            red0_score = red0_score * multi

        if "red1_gem" in left2_area:

            red1_score = red1_score * multi

        left3_area = []

        for (row,col) in midfield:

            left3_area.append(maze[row][col])

        if "yellow0_gem" in left3_area:

            yellow0_score = yellow0_score * midfield_addition

        if "yellow1_gem" in left3_area:

            yellow1_score = yellow1_score * midfield_addition

        if "yellow2_gem" in left3_area:

            yellow2_score = yellow2_score * midfield_addition

        if "yellow3_gem" in left3_area:

            yellow3_score = yellow3_score * midfield_addition

        if "red0_gem" in left3_area:

            red0_score = red0_score * midfield_addition

        if "red1_gem" in left3_area:

            red1_score = red1_score * midfield_addition

        left_lis = [yellow0_score,yellow1_score,yellow2_score,yellow3_score,red0_score,red1_score]

        best = max(left_lis)

        left_lis.remove(best)

        second_best = max(left_lis)

        left_score = best + second_best

        if context.round != 0:

            if history[len(history)-1] == "R":

                left_score = left_score * 0.95

        print(best,second_best)

        print("综合权重:", left_score)


 

    print("→ 向右方向计算")

    if maze[right_row][right_col] == "WALL":

        right_score = 0

        print("道路不可通行","\n")

    else:

        yellow0_path = api.check.path(start=(right_row, right_col), end=(yellow0_row, yellow0_col))

        yellow1_path = api.check.path(start=(right_row, right_col), end=(yellow1_row, yellow1_col))

        yellow2_path = api.check.path(start=(right_row, right_col), end=(yellow2_row, yellow2_col))

        yellow3_path = api.check.path(start=(right_row, right_col), end=(yellow3_row, yellow3_col))

        red0_path = api.check.path(start=(right_row, right_col), end=(red0_row, red0_col))

        red1_path = api.check.path(start=(right_row, right_col), end=(red1_row, red1_col))

        yellow0_score = get_update_value("yellow_gem",len(yellow0_path),yellow0_row,yellow0_col)

        yellow1_score = get_update_value("yellow_gem",len(yellow1_path),yellow1_row,yellow1_col)

        yellow2_score = get_update_value("yellow_gem",len(yellow2_path),yellow2_row,yellow2_col)

        yellow3_score = get_update_value("yellow_gem",len(yellow3_path),yellow3_row,yellow3_col)

        red0_score = get_update_value("red_gem",len(red0_path),red0_row,red0_col)

        red1_score = get_update_value("red_gem",len(red1_path),red1_row,red1_col)

        right1_area = []

        if my_row == enemy_row:

            if my_col < enemy_col:

                for n in range(enemy_col+1,my_col):

                    right1_area.append(maze[my_row][n])

        if "yellow0_gem" in right1_area:

            yellow0_score = yellow0_score * multi

        if "yellow1_gem" in right1_area:

            yellow1_score = yellow1_score * multi

        if "yellow2_gem" in right1_area:

            yellow2_score = yellow2_score * multi

        if "yellow3_gem" in right1_area:

            yellow3_score = yellow3_score * multi

        if "red0_gem" in right1_area:

            red0_score = red0_score * multi

        if "red1_gem" in right1_area:

            red1_score = red1_score * multi

        right2_area = []

        if my_row < enemy_row:

            if my_col < enemy_col:

                for n in range(my_row,enemy_row+1):

                    for i in range(my_col,enemy_col+1):

                        right2_area.append(maze[n][i])

            elif my_col > enemy_col:

                for n in range(my_row,enemy_row+1):

                    for i in range(enemy_col,my_col+1):

                        right2_area.append(maze[n][i])

        elif my_row > enemy_row:

            if my_col < enemy_col:

                for n in range(enemy_row,my_row+1):

                    for i in range(my_col,enemy_col+1):

                        right2_area.append(maze[n][i])

            elif my_col > enemy_col:

                for n in range(enemy_row,my_row+1):

                    for i in range(enemy_col,my_col+1):

                        right2_area.append(maze[n][i])

        if "yellow0_gem" in right2_area:

            yellow0_score = yellow0_score * multi

        if "yellow1_gem" in right2_area:

            yellow1_score = yellow1_score * multi

        if "yellow2_gem" in right2_area:

            yellow2_score = yellow2_score * multi

        if "yellow3_gem" in right2_area:

            yellow3_score = yellow3_score * multi

        if "red0_gem" in right2_area:

            red0_score = red0_score * multi

        if "red1_gem" in right2_area:

            red1_score = red1_score * multi

        right3_area = []

        for (row,col) in midfield:

            right3_area.append(maze[row][col])

        if "yellow0_gem" in right3_area:

            yellow0_score = yellow0_score * midfield_addition

        if "yellow1_gem" in right3_area:

            yellow1_score = yellow1_score * midfield_addition

        if "yellow2_gem" in right3_area:

            yellow2_score = yellow2_score * midfield_addition

        if "yellow3_gem" in right3_area:

            yellow3_score = yellow3_score * midfield_addition

        if "red0_gem" in right3_area:

            red0_score = red0_score * midfield_addition

        if "red1_gem" in right3_area:

            red1_score = red1_score * midfield_addition

        right_lis = [yellow0_score,yellow1_score,yellow2_score,yellow3_score,red0_score,red1_score]

        best = max(right_lis)

        right_lis.remove(best)

        second_best = max(right_lis)

        right_score = best + second_best

        if context.round != 0:

            if history[len(history)-1] == "L":

                right_score = right_score * 0.95

        print(best,second_best)

        print("综合权重:", right_score)



 

    if should_leave():

        print("第", context.round, "回合,我要离开了")

        e_row = api.get.exit("row")

        e_col = api.get.exit("col")

        return api.check.next((e_row, e_col))

    else:

        all_scores = [up_score,down_score,left_score,right_score]

        max_score = max(all_scores)

        if up_score == max_score:

            print("第", context.round, "回合,我要向上走","\n")

            history.append("U")

            return "U"

        elif down_score == max_score:

            print("第", context.round, "回合,我要向下走","\n")

            history.append("D")

            return "D"

        elif left_score == max_score:

            print("第", context.round, "回合,我要向左走","\n")

            history.append("L")

            return "L"

        elif right_score == max_score:

            print("第", context.round, "回合,我要向右走","\n")

            history.append("R")

            return "R"

稍微有点长,希望不介意。。。

本策略须搭配其他策略相互进行,不可单独使用。

还是那句话:如果想借鉴使用,麻烦先点个赞再借鉴。如果因此导致失败,本人概不负责。

作者是个小学生,所以帖子里常常有不完善的地方。
如果有什么待改进的地方请在评论区提出建议,我会感激不尽。

好了,今天的帖子到此结束!!!

AI创想家足球是一种将人工智能技术应用于足球比赛模拟的项目,它通常涉及到机器学习、深度学习、图像处理、传感器数据处理等多个技术领域。在这个项目中,AI系统能够分析比赛中的各种数据,如球员的位置、速度、传球路线、射门意图等,并根据这些数据做出预测或决策,模拟真实的足球比赛。 由于“AI创想家足球 代码”这个表述可能涉及到多个不同的实现和项目,没有一个统一的代码示例。但是,我们可以描述一个简化的代码概念,假设有一个AI足球系统,它包含以下几个关键部分: 1. 数据收集模块:负责收集比赛中的实时数据,包括球员的位置、速度、球的位置等。 2. 数据处理模块:对收集到的数据进行处理,可能包括数据清洗、特征提取等步骤。 3. 决策模型:利用机器学习算法根据处理后的数据进行决策,如预测对手的传球路线,决定最佳的防守位置或进攻策略。 4. 控制输出模块:将决策结果转化为对球员的控制指令,实现自动化的比赛行为。 以下是一个非常简化的伪代码示例,描述了上述概念中的决策模型部分: ```python # 假设我们有一个机器学习模型已经训练好 class FootballAIModel: def __init__(self): # 加载预先训练好的模型 self.model = load_pretrained_model() def make_decision(self, game_data): # 对输入的比赛数据进行处理 processed_data = preprocess(game_data) # 利用模型进行决策 prediction = self.model.predict(processed_data) return prediction # 使用AI模型进行决策 ai_model = FootballAIModel() game_data = get_current_game_data() decision = ai_model.make_decision(game_data) perform_action(decision) ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值