गुफा रेंजर्स - अंधेरे की खोज


9

आपके भूवैज्ञानिक मित्र ने आपके कार्यालय के दरवाजे को लगभग उतारा, क्योंकि वह उत्साह में आँखें फोड़ रहा था, और आपको उसके साथ एक साइट पर आने के लिए कहा जिसे उसने खोजा था। रास्ते में वह समझाता है कि उसे लगता है कि वह सचमुच सोने पर सुहागा है। केवल समस्या है, यह एक बहुत ही अस्थिर छत के साथ एक गुफा में गहरे भूमिगत दफन है। स्पेलुनकिंग के लिए जाना बहुत खतरनाक है, इसलिए वह चाहता है कि आप उसकी एक गुफा की खोज करने वाले रोबोट को उतने ही सोने के रूप में इकट्ठा कर सकें जितना वह उसे वापस खींचने से पहले कर सकता है। उन्होंने यह भी उल्लेख किया है कि उन्होंने गुफा की जांच की है और कुछ वन्यजीवों को पाया है जो रोबोट के लिए हानिकारक हो सकते हैं, और यह भी कि उन्होंने कुछ उपकरण नीचे गिरा दिए हैं जो अभी भी उपयोग करने योग्य हो सकते हैं। प्रत्येक रोबोट दो भुजाओं और कई सेंसरों से सुसज्जित है। जब आप घटनास्थल पर पहुंचते हैं, तो वह बताता है कि वह अधिक कोडर भर्ती करने की योजना बना रहा है,

अब, नीचे किरकिरा करने के लिए। सेंसर ASCII पात्रों के रूप में आपके कार्यक्रम की जानकारी देते हैं। यहां इस बात की सूची दी गई है कि प्रत्येक पात्र का क्या मतलब है और गुफा में किसी भी चीज का वर्णन हो सकता है:

Code    Name/Description

Y       Your bot
        You do things

@       Other bots
        They do other things

-       Ground
        This doesn't do things

C       Centipede
        These will bite you and leave a poison effect
        The bite will cost 1 health
        The poison effect will last for 3 turns, costing 2 health each turn

B       Bats
        If bats end up in the same space you are, your bot runs in a random direction during its turn rather than what you told it to do

L       Lion (because reasons)
        Lions deal heavy damage, 10 health, each time they attack

F       Food
        Eating this will give you 5 health
        Can only be used once

W       Water
        Drinking this will cure poison effects early
        Can only be used once

R       Revealer
        This will increase the range of your visibility to an 11x11 grid
        The extra range will only be 75% correct, but the original range won't be effected

K       Knife
        You do twice as much damage to other bots if you have a knife

G       Gold
        The whole reason you're doing this in the first place

N       Nurse Nina
        She mend you good
        Restores your health by 10 while you occupy the same space as her

}       Boulder
        You can't walk over boulders, and neither can anything else

P       Pit
        If you fall in a pit, you will be stuck for 3 turns

कितने बॉट भाग ले रहे हैं, इसके आधार पर कैवर्न का आकार बढ़ता है। यह एक 30x30 के रूप में शुरू होता है, और इसे प्रत्येक बॉट के लिए अतिरिक्त 10x10 मिलता है। तो 2 बॉट्स एक 50x50 गुफा का पता लगाएंगे।

बॉट्स 20 स्वास्थ्य के साथ शुरू होते हैं, लेकिन उनके पास स्वास्थ्य पर अधिकतम सीमा नहीं है।

इनपुट:

आप निम्न प्रारूप में STDIN के माध्यम से इनपुट प्राप्त करेंगे:

20,5,10,1,0,True,False    <-health, number gold pieces, number of turns your bot has lasted, number of until the poison wears off, number of turns until you are no longer stuck in a pit, if you have a revealer, if you have a knife
-----
-G}--
--Y-L
-C---
---B-

पहली पंक्ति में आपके बॉट के बारे में जानकारी है, और बाकी ग्रिड है जो आपके बॉट देख सकते हैं। यदि आपका बॉट गुफा की 4 दीवारों में से एक के खिलाफ है, तो आपको एक ग्रिड मिलेगा जो इस तरह दिखता है (पश्चिम के सभी रास्ते होने के मामले में):

---
}--
Y--
---
---

गुफा के चारों ओर लपेट नहीं है, और न ही आपकी दृष्टि है। गुफा की दीवारों को चिह्नित नहीं किया जाता है, केवल संकेत आपके बॉट को प्राप्त होता है कि यह एक दीवार के पास है इसका दृश्य कम हो रहा है। Revealer के साथ, आपको ऐसा कुछ मिल सकता है:

--------C--
LW--------B
---K-N-----
--------BR-
-F---------
--B--Y---@N
-W@---F----
------K-F--
----@-}----
R@---G}--}-
--------G-R

आउटपुट:

आपको प्रति मोड़ दो चालें मिलती हैं, जिन्हें आप निम्न प्रारूप में आउटपुट करते हैं:

MNNANW    <- Moves are groups of 3 characters representing the action and the direction

संभावित क्रियाएं निम्नलिखित हैं:

M    Move - Move your bot in the specified direction
A    Attack - Attack the square in the specified direction
H    Hold - Do nothing

संभावित दिशा-निर्देश निम्नलिखित हैं:

NN - North (up)
NE - Northeast (up-right)
EE - East (right)
SE - Southeast (down-right)
SS - South
SW - Southwest
WW - West
NW - Northwest

चाल को बाएं से दाएं पर लागू किया जाता है।

बदल जाता है:

निम्नलिखित फैशन में प्रगति करता है:

  1. जहर प्रभाव किसी भी खिलाड़ी पर लागू किया जाता है जिसे जहर दिया गया है

  2. गैर-बॉट चलते हैं और हमला करते हैं

    2 ए। शेर, सेंटीपीड और चमगादड़ बेतरतीब ढंग से चलते हैं

    2 बी। शेर और सेंटीपीड्स उस सब पर हमला करेंगे जो सीधे इसके समीप है (तिरछे सहित)

    2c। बल्ला प्रभाव केवल एक बॉट पर लागू होगा यदि यह बल्ले के समान स्थान पर हो

    2 डी। नर्स नीना 3 मोड़ के लिए एक स्थान पर रहेगी, और फिर एक यादृच्छिक स्थान पर कूद जाएगी।

  3. बोट्स चलते हैं

    3 ए। यदि आपका बॉट अमान्य आउटपुट देता है, तो यह नहीं चलेगा

    3 बी। आपका बॉट जितना संभव हो उतना आउटपुट द्वारा निर्दिष्ट स्थान के करीब पहुंचने की कोशिश करेगा (अधिक विस्तार के लिए नीचे नोट देखें)

    3c। एक सेंटीपीड, शेर या बैट पर एक हमला उसे मार देगा

    3 डी। चाकू के बिना दूसरे बॉट पर हमला करना 5 नुकसान करेगा, और 10 चाकू से होगा

नियम:

  1. आम भाषाओं पर टिके रहें जिन्हें OS X या Linux पर चलाया जा सकता है।

  2. आप वैकल्पिक रूप से एक फ़ाइल में 1kb डेटा से अधिक नहीं लिख सकते हैं

स्कोरिंग:

बॉट्स केवल तब तक कैवर्न में रहेंगे जब तक कि केवल एक ही रहता है, या जब तक 50 मोड़ नहीं हो जाते, जो भी पहले आता है। आपके बॉट को सोने के सिक्कों की संख्या के आधार पर आंका जाएगा कि उसने कितने सोने के सिक्के एकत्र किए और कितने चले।

यहां परीक्षण के लिए कंट्रोलर कोड डाउनलोड किया जा सकता है (उसी फोल्डर में "बॉट्स" नामक एक फोल्डर बनाएं जिसे आप इसे डाउनलोड करते हैं, और अपने बॉट को "बॉट्स" के अंदर डालते हैं) आपको इसे चलाने के लिए NumPy की आवश्यकता होगी। इसके माध्यम से खुदाई करने के लिए स्वतंत्र महसूस करें, लेकिन आपको गंदगी का बहाना करना होगा ...

यहाँ एक यादृच्छिक बॉट के लिए कुछ कोड है:

#!/usr/bin/python
import random as r

a = ['M','A','H']
d = ['NN','NE','EE','SE','SS','SW','WW','NW']

print(a[r.randint(0,2)]+d[r.randint(0,7)]+a[r.randint(0,2)]+d[r.randint(0,7)])

**** आपका बॉट हमेशा सामान्य दिशा में आगे बढ़ेगा जो आपका आउटपुट निर्दिष्ट करता है, लेकिन अगर यह एक चट्टान या दीवार से बाधित होता है, तो सटीक दिशा परिस्थिति पर निर्भर करती है। उदाहरण के लिए, यदि आपका बॉट दीवार की तरह है, तो:

---
}--
Y--
---
---

और आपका आउटपुट है

MNWMSW

आपका बॉट एक स्थान नीचे चला जाएगा। यह उत्तर या पश्चिम की ओर नहीं जा सकता था, इसलिए इस कदम का कोई प्रभाव नहीं पड़ा। यह दक्षिण को स्थानांतरित कर सकता था (और किया) लेकिन पश्चिम को नहीं हिला सका। हालाँकि, यदि आपके बॉट ने पूर्वोत्तर को स्थानांतरित करने की कोशिश की है, तो यह सीधे उस स्थान पर जाएगा (विकर्ण आंदोलन विकर्ण है, प्रक्रियात्मक नहीं)

लीडरबोर्ड

ये 4 खेलों के औसत अंक हैं।

The bot of Survival:    54.75
Coward:                 52.25
Pufferfish:             50.00
Randombot:              50.00
Indiana Jones:          47.50
TheoremBot:             46.50

प्रत्येक बॉट में कितना स्वास्थ्य है? और कावे का किनारा कैसा दिखता है?
कॉनर ओ'ब्रायन

वे 20 से शुरू करते हैं और जितना चाहें उतना इकट्ठा कर सकते हैं। ऊपर इस जानकारी को जोड़ा
बीनस्टॉक

Cavern के किनारों को चिह्नित नहीं किया गया है, आपके प्रोग्राम को केवल बिट्स मिलेंगे जिन्हें आप संभावित रूप से चल सकते हैं।
बीनस्टॉक

क्या आप वास्तव में अपने स्वास्थ्य को नहीं जानते हैं?
pppery

क्या आप बॉट की दृष्टि की लंबाई और चौड़ाई इनपुट कर सकते हैं?
18 मई को लीजनमोन 978

जवाबों:


4

इंडियाना जोन्स, पायथन 2

यह बॉट किसी भी चीज से डरता नहीं है। यह सोना पाने की कोशिश करेगा; और अगर यह किसी को नहीं मिल सकता है, तो यह विरोधियों को चाकू से मारने की कोशिश करेगा।

#!/usr/bin/env python
import sys
import random
data = sys.stdin.readlines()
health, gold, turns, poison_remaining, pit_remaining, revealer, knife = eval(data[0])
lines = data[1:]

myloc = [-1, -1]

width, height = len(lines[0]), len(lines)

for y, line in enumerate(lines):
    if line.find('Y')>-1:
        myloc = [line.index('Y'), y]
if myloc[0]<width/2:
    padding = int(width/2-myloc[0])
    lines = ['-'*padding+line for line in lines]
    myloc[0]+=padding
elif myloc[0]>width/2+1:
    padding = int(myloc[0]-width/2-1)
    lines = [line+'-'*padding for line in lines]

if myloc[1]<height/2:
    padding = int(height/2-myloc[1])
    lines = ['-'*width]*padding + lines
    myloc[1]+=padding
elif myloc[1]>height/2+1:
    padding = int(myloc[1]-height/2-1)
    lines = lines + ['-'*width]*padding

uddirections = {1:'N',0:'',-1:'S'}
lrdirections = {1:'E',0:'',-1:'W'}

golds = {}
for y, line in enumerate(lines):
    if 'G' in line:
        x = line.index('G')
        direction = ((uddirections[max(min(myloc[1]-y,1),-1)]+lrdirections[max(min(x-myloc[0],1),-1)])*2)[:2]
        distance = max(abs(myloc[0]-x), abs(myloc[1]-y))
        golds[distance] = direction

bots = {}
for y, line in enumerate(lines):
    if '@' in line:
        x = line.index('@')
        direction = ((uddirections[max(min(myloc[1]-y,1),-1)]+lrdirections[max(min(x-myloc[0],1),-1)])*2)[:2]
        distance = max(abs(myloc[0]-x), abs(myloc[1]-y))
        bots[distance] = direction

foods = {}
for y, line in enumerate(lines):
    if 'F' in line:
        x = line.index('F')
        direction = ((uddirections[max(min(myloc[1]-y,1),-1)]+lrdirections[max(min(x-myloc[0],1),-1)])*2)[:2]
        distance = max(abs(myloc[0]-x), abs(myloc[1]-y))
        foods[distance] = direction

knives = {}
for y, line in enumerate(lines):
    if 'K' in line:
        x = line.index('K')
        direction = ((uddirections[max(min(myloc[1]-y,1),-1)]+lrdirections[max(min(x-myloc[0],1),-1)])*2)[:2]
        distance = max(abs(myloc[0]-x), abs(myloc[1]-y))
        knives[distance] = direction

if golds:
    direction = golds[min(golds.keys())]
elif not knife and knives:
    direction = knives[min(knives.keys())]
elif health<20 and foods:
    direction = foods[min(foods.keys())]
elif bots and knife:
    direction = bots[min(bots.keys())]
    if min(bots.keys())==1:
        print ('A'+direction)*2
        sys.exit(0)
    elif min(bots.keys())==2:
        print 'M'+direction+'A'+direction
        sys.exit(0)
else:
    print ('M'+random.choice('NS')+random.choice('NEWS'))*2
    sys.exit(0)
print ('M'+direction)*2

इस कार्य को करने के लिए बस एक चीज को बदलना line.index('Y')होगा - यदि "Y" लाइन में नहीं है, तो एक एरर फेंक देगा, लेकिन line.find('Y')यदि "Y" लाइन में नहीं है तो -1 लौटा देगा। अन्यथा, यह बहुत अच्छा है!
बीनस्टॉक

आप कभी-कभी गन्ने का उत्पादन करते हैं MSNMSN, जो अमान्य है।
21

3

कायर, अजगर ३

एक कायर हमेशा संभावित खतरों से चलाता है।

हालांकि, अगर वह सुपर मजबूत महसूस करता है, तो वह अचानक एमोक चलाएगा और उसके पास सब कुछ छुरा घोंप देगा।

वर्तमान कार्यान्वयन के साथ समस्या यह है कि चाल आज्ञाओं को बिना ज्ञान के जारी किया जाता है चाहे वह पहली या दूसरी चाल हो।

#!/usr/bin/env python3.4

import sys, random


class Coward():
  """
  A coward always runs from potential threats.

  However, if he feels super strong, he will suddenly run amok 
  and stab everything near him.  
  """
  def __init__(self, hp, gold, turn, poison, pit, revealer, knife):
    self.hp=int(hp)
    self.gold=int(gold)
    if knife=="True": self.knife=True
    else: self.knife=False    
    self.pit=int(pit)
    self.poison=int(poison)

  def readGrid(self, grid):
    self.grid=grid.split("\n")
  @property
  def _confidence(self):
    return self.hp+5*self.knife-2*self.poison
  @property
  def _lineOfY(self):
    for i, line in enumerate(self.grid):
      if "Y" in line:
        return i
  @property
  def _colOfY(self):
    return self.grid[self._lineOfY].index("Y")
  @property
  def _maxX(self):
    return len(self.grid)-1
  @property
  def _maxY(self):
    return len(self.grid[0])-1
  def move(self, step):
    d = {'NN':(0,-1),'NE':(1,-1),'EE':(1,0),'SE':(1,1),'SS':(0,1),'SW':(-1,1),'WW':(-1,0),'NW':(-1,-1)}
    c2d={(0,-1):'NN',(1,-1):'NE',(1,0):"EE",(1,1):"SE",(0,1):"SS",(-1,1):"SW",(-1,0):"WW",(-1,-1):"NW"}
    #Don't move into wall/ boulder/ pit
    #print(d, file=sys.stderr)
    for k,v in list(d.items()):
      x=self._lineOfY+v[0]
      y=self._colOfY+v[1]
      #print (k, v ,x , y, file=sys.stderr)
      if x<0 or y<0 or x>self._maxX or y>self._maxY:
        #print ("Out of bounds: ", k, file=sys.stderr)
        del d[k]
      elif self.grid[x][y]=="}" or self.grid[x][y]=="P":
        del d[k]
    #Always avoid bats, and enemys
    for dx in range(-2,3):
      for dy in range(-2,3):
        x=self._lineOfY+dx
        y=self._colOfY+dy
        if x<0 or y<0 or x>self._maxX or y>self._maxY:
          continue;
        if self.grid[x][y] in ["B", "L", "C", "@"]:
          for k in self._toDirection(dx, dy):
            if k in d: del d[k] #Too many threats from all sides can paralyze the Coward: nowhere to go...
    #print(d, file=sys.stderr)
    tomove=[]
    #Neighboring fields
    for dx in [-1,1]:
      for dy in [-1,1]:
        x=self._lineOfY+dx
        y=self._colOfY+dy
        if x<0 or y<0 or x>self._maxX or y>self._maxY:
          continue
        if self.poison>0 and self.grid[x][y]=="W":
          for k,v in d.items():
            if v==(dx,dy):
              tomove.append(k)
        if self.grid[x][y]=="N": #Always go to nurse, even if dangerous
          tomove.append(c2d[(x,y)])
        if self.grid[x][y] in ["F","K","G"]: #Go to Food, Knife or Gold, if save
          for k,v in d.items():
            if v==(dx,dy):
              tomove.append(k)
    #Further away: Go towards food, knife and gold and Nina if save.
    for target in ["N", "F", "G", "K"]:
      for dx in [-2,2]:
        for dy in [-2,2]:
          x=self._lineOfY+dx
          y=self._colOfY+dy
          if x<0 or y<0 or x>self._maxX or y>self._maxY:
            continue
          if self.grid[x][y]==target:
            l=[ k for k in self._toDirection(dx,dy) if k in d]
            if l: tomove.append(random.choice(l))
    s=list(d.keys())
    random.shuffle(s)
    tomove+=s
    try:
      return "M"+tomove[step-1]
    except IndexError:
      return ""
  def attack(self, step):    
    c2d={(0,-1):'NN',(1,-1):'NE',(1,0):"EE",(1,1):"SE",(0,1):"SS",(-1,1):"SW",(-1,0):"WW",(-1,-1):"NW"}
    #If Bot next to you: always attack
    for k,v in c2d.items():
      x=self._lineOfY+k[0]
      y=self._colOfY+k[1]
      if x<0 or y<0 or x>self._maxX or y>self._maxY:
        continue
      if self.grid[x][y]=="@":
        return "A"+v
    #If Bot or monster could come closer: attack potential new position
    attDir={(-2,-2):["NW"], (-2,-1):["NW","WW"], (-2,0):["WW","NW","SW"], (-2,1):["WW","SW"], (-2,2):["SW"],(-1,-2):["NW","NN"], (-1,2):["SW","SS"], (0,2):["SW","SS","SE"],(0,-2):["NW","NN","NE"],(1,-2):["NN","NE"],(1,2):["SS","SE"],(2,-2):["NE"],(2,-1):["NE","EE"], (2,0):["NE","EE","SE"], (2,1):["EE","SE"], (2,2):["SE"]}
    for k,v in attDir.items():
      x=self._lineOfY+k[0]
      y=self._colOfY+k[1]
      if x<0 or y<0 or x>self._maxX or y>self._maxY:
        continue
      if self.grid[x][y] in ["@","L","C","B"]:
        return "A"+random.choice(v)
    return ""
  def _toDirection(self,dx,dy):
    if dx<0:
      if dy<0:
        return ["WW","NW","NN"]
      elif dy==0:
        return ["WW","NW","SW"]
      elif dy>0:
        return ["WW","SW","SS"]
    elif dx>0:
      if dy<0:
        return ["EE","NE","NN"]
      elif dy==0:
        return ["EE","NE","SE"]
      elif dy>0:
        return ["EE","SE","SS"]
    elif dx==0:
      if dy<0:
        return ["NN","NE","NW"]
      elif dy==0:
        return []
      elif dy>0:
        return ["SS","SE","SW"]
  def _nearBat(self):
    for dx in range(-2,3):
      for dy in range(-2,3):
        x=self._lineOfY+dx
        y=self._colOfY+dy
        if x<0 or y<0:
          continue;
        if self.grid[x][y]=="B":
          return True
    return False
  def makeTurn(self):
    try:
      command=""
      #If stuck, just attack
      if self.pit:
        command+=self.attack(1)+self.attack(2)
      #Always run from bats
      if self._nearBat:
        command+=self.move(1)+self.move(2)
      #If high-confidence: attack
      if self._confidence>30:
        command+=self.attack(1)+self.attack(2)
      #Else: Move somewhere
      command+=self.move(1)+self.move(2)
      #Just in case, two random attacks
      d = ['NN','NE','EE','SE','SS','SW','WW','NW']
      a=random.choice(d)
      b=random.choice([ x for x in d if x!=a])
      command+="A"+a+"A"+b
      return command[:6]
    except Exception as e:
      #print (e, file=sys.stderr)
      #Attacking is better than nothing
      d = ['NN','NE','EE','SE','SS','SW','WW','NW']
      a=random.choice(d)
      b=random.choice([ x for x in d if x!=a])
      return "A"+a+"A"+b


info=sys.stdin.readline()
grid=sys.stdin.read()
info=info.split(",")
bot=Coward(*info)
bot.readGrid(grid)
t=bot.makeTurn()
#print(t, file=sys.stderr)
print(t)

3

अस्तित्व का बॉट - पायथन 2

from __future__ import print_function
health,gold,survived,poison,pit,revealer,knife = input()
if pit:
    exit()
#Yes, this is python 2, despite the use of input()
lines = []
try:
    while True:
        lines.append(raw_input())
except EOFError:
    pass
CMOVES={"NW":(-1,-1),"NN":(-1,+0),"NE":(-1,+1),
        "WW":(+0,-1),             "EE":(-0,+1),
    "SW":(+1,-1),"SS":(+1,+0),"SE":(+1,+1),
}
MOVES={v:k for k,v in CMOVES.iteritems()}
import sys
def get_your_pos():
    for row,line in enumerate(lines):
        for col,square in enumerate(line):
            if square == "Y":
                return row,col
    raise ValueError("Your bot is not present.")
def isnearby(thing,p=None):
    your_pos = p or get_your_pos()
    for move in MOVES:
        yp = your_pos[0]+move[0],your_pos[1]+move[1]
        try:
            if yp[0] >= 0 and yp[1] >= 0 and lines[yp[0]][yp[1]] == thing:
                return move
        except IndexError:
            #Edge of cavern
            pass
for turn in range(2):
    import random
    nprio = .5
    if health > 25:
        nprio -= .2
    elif health < 10:
        nprio += .3
    if poison:
        nprio += .18
    #heal
    motive = how = None
    if random.random() < nprio:
        nurse = isnearby("N")
        if nurse:
            motive = "M"
            how = MOVES[nurse]
        elif random.random() < nprio:
            food = isnearby("F")
            if food:
                motive = "M"
                how = MOVES[food]
    #cure poison
    if poison and not motive:
        water = isnearby("W")
        if water:
            motive = "M"
            how = MOVES[water]
    if not motive:
        #Kill lions, bats, and centipedes
        for animal in ("L","B","C"):
            animal = isnearby(animal)
            if animal:
                motive = "A"
                how = MOVES[animal]
                y = get_your_pos()
                y = y[0]+animal[0],y[1]+animal[1]
                lines = map(list,lines)
                lines[y[0]][y[1]] = "-"
                break
        else:
            #Pick up knives
            if not knife:
                knife = isnearby("K")
                if knife:
                    motive = "M"
                    how = MOVES[knife]
            #Attack other bots
            else:
                prey = isnearby("@")
                if prey:
                    motive = "A"
                    how = MOVES[prey]
    #Get gold
    gold = isnearby("G")
    if gold and not motive:
        motive = "M"
        how = MOVES[gold]
    def isvalidmove(c):
        c = CMOVES[c]
        y = get_your_pos()
        y=(y[0]+c[0],y[1]+c[1])
        if y[0] >= 0 and y[1] >= 0:
            try:
                lines[y[0]][y[1]]
            except LookupError:
                pass
            else:
                return True
    if turn and not motive:
        motive = "M"
        while not (how and how not in (isnearby("}"),isnearby("P"),isnearby("@"))\
              and isvalidmove(how)):
            how = random.choice(CMOVES.keys())
    if not motive:break
    if not turn and motive == "M":
        lines = map(list,lines)
        yp = get_your_pos()
        lines[yp[0]][yp[1]] = "-"
        yp=[yp[0]+CMOVES[how][0],yp[1]+CMOVES[how][1]]
        lines[yp[0]][yp[1]] = "Y"
    print(motive+how,end="")
else:
    exit()
#Nothing found on first move
def isvaguelynearby(thing):
    your_pos = get_your_pos()
    for move in MOVES:
        yp = your_pos[0]+move[0],your_pos[1]+move[1]
        try:
            if yp[0] >= 0 and yp[1] >= 0 and board[yp[0]][yp[1]] != "P":
                dest = isnearby(thing,yp)
                if dest:
                    return move,dest
        except IndexError:
            #Edge of cavern
            pass
if random.random() < nprio:
    dests = isvaguelynearby("N")
    if not dests and random.random() < nprio:
        dests = isvaguelynearby("F")
    if dests:
        m1,m2 = MOVES[dests[0]],MOVES[dests[1]]
        print("M" + m1 + "M" + m2)
        exit()
dests = (poison and isvaguelynearby("W")) or (not knife and isvaguelynearby("K"))\
    or isvaguelynearby("G")
prey = isvaguelynearby("L") or isvaguelynearby("B") or isvaguelynearby("C") or \
       (knife and isvaguelynearby("@"))
if dests:
    m1,m2 = MOVES[dests[0]],MOVES[dests[1]]
    print("M" + m1 + "M" + m2)
elif prey:
    m1,m2 = MOVES[prey[0]],MOVES[prey[1]]
    print("M" + m1 + "A" + m2)
else:
    how = None
    while not (how and how not in     (isnearby("}"),isnearby("P"),isnearby("@"))\
          and isvalidmove(how)):
        how = random.choice(CMOVES.keys())
    print("M"+how,end="")
    lines = map(list,lines)
    yp = get_your_pos()
    lines[yp[0]][yp[1]] = "-"
    yp=[yp[0]+CMOVES[how][0],yp[1]+CMOVES[how][1]]
    lines[yp[0]][yp[1]] = "Y"
    while not (how and how not in (isnearby("}"),isnearby("P"),isnearby("@"))\
          and isvalidmove(how)):
            how = random.choice(CMOVES.keys())
    print("M"+how)

संपादित करें: बेहतर गड्ढे से बचाव को जोड़ा।


2

पफरफिश, पायथन 3+

मैं सिर्फ वह व्यक्ति हूं।

#!/usr/bin/env python3.4
import random
def select():
 return "A"+["NN","NE","EE","SE","SS","SW","WW","NW"][random.randint(0,7)]
print(select()+select())

इस बॉट में आत्म-निर्वाह का उद्देश्य है। अगर मेरे पास समय हो तो मैं बाद में गोल्फ की मांग कर सकता हूं।
कॉनर ओ'ब्रायन

यह आपके कोड को थोड़ा लंबा कर देगा, लेकिन पफरफिश एक ही मोड़ पर दो बार हमला करने में सक्षम है यदि यह अधिक घातक होना चाहता है
बीनस्टॉक

@ TheBststalk ओह्ह स्वीट!
कॉनर ओ'ब्रायन

आपको एहसास है कि इस बॉट को कभी भी सोना नहीं मिलेगा, और अन्य सभी बॉट इसकी "मार आभा" में नहीं
भटकेंगे

@ppperry मुझे इसका एहसास है; यह मुख्य रूप से गेंद को लुढ़काने के लिए था; इसे जीतने के लिए नहीं, बल्कि जीवन को थोड़ा और कठिन बनाने के लिए किया जाता है। जैसे, ब्लैक हैट मैन
कॉनर ओ'ब्रायन
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.