圣诞派对代码
import api #圣诞礼物降临小镇,bell铃铛,candy糖果,cookie饼干,tree圣诞树,star星星 #使用api.set_item_name( )为物品命名,方便后续调用。 api.set_item_name( item101 = "bell", item102 = "candy", item103 = "cookie", item104 = "tree", item105 = "star", item201 = "box" ) #主程序每回合自动调用玩家定义的update(context)函数,函数返回值(U, D, L, R, S )使企鹅向某方向(上 ,下 ,左 ,右 ,停)移动 def update(context): m_row = context.me.row m_col = context.me.col exit_row = context.exit.row exit_col = context.exit.col my_energy = context.me.energy path_exit = api.check.path(start=(m_row, m_col), end=(exit_row, exit_col)) exit_distance = len(path_exit) - 1 if my_energy <= (exit_distance + 1): direction = api.check.next(end = (exit_row , exit_col)) elif context.me.score > context.players[1].score+100 and context.players[1].row <=7: if context.players[1].row <3 : direction = api.check.next(end=(3, context.players[1].col)) else: direction = api.check.next(end=(context.players[1].row + 1, context.players[1].col)) else: closest_gem = api.check.closest_item(context.items["box"]+context.items["star"]+context.items["tree"]+context.items["cookie"]+context.items["candy"]+context.items["bell"]) direction = api.check.next(end = (closest_gem.row , closest_gem.col)) return direction