एक निर्जन द्वीप पर खजाना शिकार


13

परिचय

आप कुछ नौकरों के साथ एक निर्जन द्वीप पर फंसे हुए हैं और खजाने का शिकार हो रहे हैं। अब जितना खोजता है, उतना ही खजाना पाता है। जितने कम लोग खोज करते हैं, उतना अधिक प्रत्येक व्यक्ति पाता है।

सीमित आपूर्ति के कारण, नेता ने फैसला किया है कि समूह के एक चौथाई तक कुछ लोगों को प्रत्येक रात मरने के लिए छोड़ दिया जाएगा। उन्होंने किसी को भी यह बताने का फैसला नहीं किया है कि समय से पहले किसी भी दिन कितने लोग मारे जाएंगे।

आप 5 लोगों के एक छोटे समूह के नियंत्रण में हैं, जो आपके लिए खजाना खोजने के लिए शिविर से बाहर निकलेंगे।

उद्देश्य

इस प्रतियोगिता का उद्देश्य जितना संभव हो उतना खजाना एकत्र करना है। हर वह मोड़ जो आपके नौकर शिविर में लौटने की कोशिश नहीं करते हैं, वे एक निश्चित संख्या में खजाने के टुकड़े पाएंगे। आपके सेवक अलग-अलग समय पर शिविर में लौट सकते हैं।

प्रत्येक मोड़ जो एक कार्यकर्ता खजाने की खोज करने के लिए बाहर रहता है, श्रमिक को 1+Rखजाने के टुकड़े मिलते हैं , जहां Rश्रमिकों की संख्या (सभी बॉटों में से) पहले से ही शिविर में वापस आ गई है। इस गणना में मृत बॉट कारक नहीं हैं।

प्रत्येक दिन के शुरू में, एक यादृच्छिक संख्या ( n) से 2करने के लिए max(3, floor(num_live_players/4))चुना जाएगा। (1 दिन 10 खिलाड़ियों के लिए, यह है 2करने के लिए max(3,50/4)=12। 1 दिन पर 20 खिलाड़ियों के लिए, यह हो सकता है 2के लिए max(3,100/4)=25।) यह संख्या खिलाड़ी हैं जो उस दिन के लिए मरने के लिए छोड़ दिया जाएगा की संख्या का प्रतिनिधित्व करता है, और अपने कार्यक्रम के लिए नहीं दिया जाएगा ।

यदि एक नौकर nलौटने के लिए अंतिम लोगों में से एक है , तो वह / वह मर जाएगा और उस खजाने को हस्तांतरित करने में असमर्थ होगा जो उसने आपके कब्जे में पाया था। इसके अलावा, नौकर बाकी साहसिक कार्य के लिए खजाने की खोज में भाग लेने में असमर्थ होगा।

आपका अंतिम स्कोर आपके द्वारा प्रति एडवेंचर (कंट्रोलर को चलाने) के लिए प्राप्त औसत खजाना है।

यदि अधिक लोग खुले स्लॉट की तुलना में उसी मोड़ पर शिविर में लौटने का प्रयास करते हैं, तो यादृच्छिक संख्या निर्धारित करेगी कि कौन अंदर जाता है और कौन मर जाता है।

इस द्वीप पर एक दिन सूर्योदय से सूर्यास्त तक 30 चक्कर लगते हैं। चूंकि रात में कई खतरनाक जानवर होते हैं, इसलिए सूर्यास्त तक लौटने में विफलता का मतलब है कि आपको शिविर में नहीं जाने दिया जाएगा।

इनपुट आउटपुट

सिमुलेशन की संपूर्णता के लिए आपका कार्यक्रम चलना चाहिए।

सिमुलेशन की शुरुआत में, INDEX Iइनपुट किया जाएगा, जहां Iआपके बॉट का सूचकांक है (यह सूचकांक 1 अप से गिना जाता है)।

प्रत्येक दिन की शुरुआत में, START_DAY D/Nआपके प्रोग्राम में इनपुट किया जाएगा, जहां Dदिन की संख्या (शुरुआत से 1) है, और Nइसके बराबर है max(3, floor(num_live_players/4)), जो कि उस विशेष दिन पर मरने वाले लोगों की अधिकतम संख्या है।

प्रत्येक मोड़ के शुरू में, START_TURN Tआपके प्रोग्राम पर इनपुट किया जाएगा, जहां Tटर्न नंबर (शुरू से 1) है।

एक बार जब आपका प्रोग्राम इसे प्राप्त कर लेता है, तो उसे आपके सेवकों की चालों की सूची के साथ प्रतिक्रिया करनी चाहिए, प्रत्येक को अल्पविराम द्वारा अलग किया गया।

मान्य चालें हैं:

  • R: शिविर में लौटने का प्रयास करें।
  • S: खजाने की तलाश में रहो।
  • N: नौकर पहले ही मर चुका है या शिविर में है।

अमान्य चाल दर्ज करने पर व्याख्या की जाएगी जैसे Sकि बॉट जीवित है और शिविर में नहीं है, और Nअन्यथा।

प्रत्येक मोड़ के अंत में, आपके प्रोग्राम में एक स्ट्रिंग दी जाएगी:

END_TURN [Turn #] [Bot 1 Moves] [Bot 2 Moves] ...

जहां प्रत्येक बॉट के नौकरों की चाल अल्पविराम द्वारा अलग की जाती है।

ये चालें निम्नलिखित में से एक होंगी:

  • R: उस मोड़ को कैंप करने के लिए सफलतापूर्वक लौटे।
  • r: उस मोड़ पर शिविर में लौटने में विफल।
  • S: फिर भी खजाने की तलाश में।
  • D: पहले वाले मोड़ पर मर गया।
  • N: पहले से ही शिविर में वापस आ गया।

बॉट और नौकर पूरे सिमुलेशन में एक ही क्रम में रहते हैं।

उदाहरण के लिए:

INDEX 2
....
END_TURN 8 N,N,N,N,N r,r,r,r,D D,D,D,N,R S,D,D,N,D

यहां, आप दूसरे बॉट ( r,r,r,r,r) हैं, जिन्होंने सभी चार नौकरों को वापस करने की कोशिश की है जो अभी भी जीवित हैं (और चारों तरफ से असफल हो गए हैं)। बॉट 1 के नौकर सब वापस शिविर में हैं। बॉट 3 में तीन मृत नौकर, शिविर में एक और पीछे और पांचवें नौकर थे जो सफलतापूर्वक वापस आ गए। बॉट 4 में एक नौकर है जो रुका था (और मर जाएगा, क्योंकि यह एक दिन का आखिरी मोड़ है), शिविर में एक नौकर और तीन मृत नौकर थे।

इनमें से प्रत्येक स्ट्रिंग्स के बाद, जब तक कि दिन के अंत में एक स्ट्रिंग सिग्नलिंग भी आउटपुट नहीं किया गया है (नीचे देखें), आपका प्रोग्राम कॉमा द्वारा अलग किए गए आपके सेवकों की अगली चालों को आउटपुट करने के लिए है। सभी नौकरों का हिसाब होना चाहिए ( Nयदि पहले से शिविर में हैं, और Dयदि पहले ही मर चुके हैं)। अवैध चालों को माना जाएगा जैसे Sकि नौकर पहले ही शिविर में नहीं है। उदाहरण:

N,N,S,S,R

जिसका मतलब है:

Servant # | Action
     1    | Do nothing.
     2    | Do nothing.
     3    | Stay put (keep looking for treasure).
     4    | Stay put (keep looking for treasure).
     5    | Try to return to camp.

एक दिन के अंत में, निम्नलिखित तार को अंतिम मोड़ के ENDस्ट्रिंग के बाद पारित किया जाएगा , जो सभी को सूचित करता है कि कौन जीवित है:

END_DAY [Day #] [Bot 1 Status] [Bot 2 Status] 

जहां स्थिति किसी भी A(जीवित) या D(मृत) की अल्पविराम से अलग की गई सूची है । अगले दिन के तुरंत बाद शुरू होता है।

जब 6 से कम जीवित नौकर होते हैं तो अनुकरण समाप्त हो जाता है। आपका कार्यक्रम अनुकार के अंत में निम्नलिखित इनपुट प्राप्त करेगा:

EXIT

नियमों / विवरण

  • केवल उन स्थानों पर जाता है जहां आपकी क्रिया है S, तो आप खजाना पाएंगे।
  • सिमुलेशन चलाने की संख्या: 1000 बार
  • आपके कार्यक्रम को चालें निर्धारित करने के लिए 1 सेकंड से अधिक नहीं लेना चाहिए।
  • आपका कार्यक्रम जल्दी बाहर नहीं निकलना चाहिए; इसे ठीक एक बार शुरू किया जाएगा।
  • सुनिश्चित करें कि आउटपुट बफर (यदि लागू हो) प्रत्येक आउटपुट के बाद फ्लश हो जाए।
  • फ़ाइलें आपके बॉट के फ़ोल्डर ( ./players/BotName/) में लिखी जा सकती हैं । आपका बॉट नाम है जो भी आप अपने बॉट का नाम रखते हैं, सभी गैर-अल्फ़ान्यूमेरिक वर्णों को हटा दिया जाता है और कैमलकेस में लिखा जाता है। प्रविष्टियां नियंत्रक के रनों के बीच डेटा को बचा सकती हैं, क्योंकि रन क्रमिक रूप से किए जाते हैं।
  • आपका प्रोग्राम प्राप्त करने के बाद बाहर निकलना चाहिए EXIT
  • वे प्रोग्राम जो त्रुटियों या आउटपुट को अमान्य पाठ संकलित या फेंकने में विफल होते हैं (कॉमा द्वारा अलग किए गए 5 वर्णों के प्रारूप में नहीं) को प्रतियोगिता से बाहर रखा जा सकता है। एक newline को प्रत्येक आउटपुट का पालन करना चाहिए।
  • नियंत्रक GitHub पर पाया जा सकता है

कृपया बॉट नाम, भाषा + संस्करण, कोड और कमांड (यदि लागू हो) को संकलित करें और अपना बॉट चलाएं।

उदाहरण

कार्यक्रम द्वारा उत्पादित पाठ यहाँ उपसर्ग के साथ है a >। आपका प्रोग्राम इस चरित्र को आउटपुट नहीं करना चाहिए।

INDEX 2
START_DAY 1/3
START_TURN 1
>S,S,S,S,S
END_TURN 1 S,R,S,S,S S,S,S,S,S
START_TURN 2
>S,S,S,S,S
END_TURN 2 S,N,S,R,S S,S,S,S,S
START_TURN 3
>R,R,S,S,S
END_TURN 3 R,N,R,N,R R,R,S,S,S
START_TURN 4
>N,N,S,S,S
END_TURN 4 N,N,N,N,N N,N,S,S,S
START_TURN 5
>N,N,R,R,R
END_TURN 5 N,N,N,N,N N,N,r,r,R
END_DAY 1 A,A,A,A,A A,A,D,D,A
START_DAY 2/3
START_TURN 1
>S,S,N,S,N
END_TURN 1 R,R,R,R,R S,S,D,D,N
END_DAY 2 A,A,A,A,A D,D,D,D,D
EXIT

उपरोक्त उदाहरण के लिए अंक हैं:

Bot#    Day 1   Day 2   Total
1       10      0       10
  S1    1+2     0       3
  S2    0       0       0
  S3    1+2     0       3
  S4    1       0       1
  S5    1+2     0       3

2       20      0       20
  S1    1+2     0       3
  S2    1+2     0       3
  S3    0       0       0
  S4    0       0       0
  S5    1+2+3+8 0       14

विजेता इसलिए खिलाड़ी है, बॉट 2. ध्यान दें कि विजेता को पूर्ण अंत तक जीवित रहने की आवश्यकता नहीं है। (यह भी ध्यान दें कि खिलाड़ी 1 दिन 30 साल की उम्र तक रह सकता था, क्योंकि शिविर तब तक पूरा नहीं होगा जब तक खिलाड़ी एक और बॉट वापस नहीं भेज देता)।

स्कोर

Bot               Score
Bob               2939.422
Statisticians     2905.833
Morning Birds     1652.325
Evolved           1578.285
Slow Returners    1224.318
Wandering Fools   1065.908
Randomizers       735.313
Drunkards         0     
Plague            0

लॉग गिटहब पर उपलब्ध हैं । प्रत्येक परीक्षण के परिणाम इस Google स्प्रेडशीट पर उपलब्ध हैं


यदि कोई नौकर वापस नहीं आता है, तो क्या वह इस दिन मरने वाले लोगों की संख्या में गिना जाता है?
ईगलवी_अट्टनम

@EagleV_Attnam दिन या तो समाप्त हो जाता है जब वहाँ पर्याप्त नौकर लौट आए हैं, या 30 मोड़ बीत चुके हैं, जिसमें हर कोई जो वापस नहीं लौटा है, वह मृत्यु से पहले की निर्धारित संख्या की परवाह किए बिना मर जाएगा।
es1024

सही है, कि मूर्खतापूर्ण था, क्षमा करें।
ईगलवी_अट्टनम

यदि कोई नौकर शिविर में लौटता है, तो क्या वह अब तक मिले खजाने को वितरित कर सकता है और फिर उसी दिन फिर से खोज करने के लिए निकल सकता है?
लॉज नाइट

1
@ मायकेस्वीनी नं। एक बार एक नौकर लौटा, तो वह रुक गया।
es1024

जवाबों:


5

बॉब - C ++

#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>

using namespace std;

int compare(int i, int j)
  {
  if (i < j)
    return (-1);
  if (i == j)
    return (0);
  if (i > j)
    return (1);
  }

int main()
  {
  int index;
  int day;
  int turn;
  int slash_index;
  int to_die;
  int num_alive;
  int mine_alive;
  int turn_to_return;
  bool returned;
  string line;
  vector<int> last_returns;
  vector<int> today_returns;

  getline(cin, line);

  if (line.compare(0, 6, "INDEX ") != 0)
    {
    cerr << "INVALID INDEX LINE \"" << line << "\"" << endl;

    return (-1);
    }

  index = atoi(line.substr(6).c_str()) - 1;

  while (1) // Day loop
    {
    getline(cin, line);
    if (line.compare(0, 4, "EXIT") == 0)
      {
      return (0);
      }
    else if (line.compare(0, 9, "START_DAY") != 0 || (slash_index = line.find('/')) == string::npos)
      {
      cerr << "INVALID START_DAY \"" << line << "\"" << endl;
      return (-1);
      }

    day = atoi(line.substr(10, slash_index - 10).c_str());
    to_die = atoi(line.substr(slash_index + 1, line.length() - slash_index - 1).c_str());

    if (day != 1)
      {
      if (to_die > num_alive)
        {
        turn_to_return = 30;
        }
      else
        {
        turn_to_return = last_returns[last_returns.size() - to_die] - 1;
        }
      }

    returned = false;

    for (turn = 1; turn <= 30; ++turn)
      {
      getline(cin, line);

      if (line.compare(0, 4, "EXIT") == 0)
        {
        return (0);
        }
      if (line.compare(0, 7, "END_DAY") == 0)
        {
        goto end_day;
        }
      if (line.compare(0, 10, "START_TURN") != 0)
        {
        cerr << "INVALID START_TURN \"" << line << "\"" << endl;
        }

      if (day == 1)
        {
        switch (compare(turn, 30))
          {
            case -1:
              cout << "S,S,S,S,S" << endl;
              break;

            case 0:
              cout << "R,R,R,R,R" << endl;
              break;

            case 1:
              cout << "N,N,N,N,N" << endl;
              break;
          }
        }
      else
        {
        if (returned)
          {
          cout << "N,N,N,N,N" << endl;
          }
        /*
        else if (num_alive - today_returns.size() < to_die)
          {
          cout << "R,R,R,R,R" << endl;
          returned = true;
          }
        */
        else if (turn >= turn_to_return)
          {
          cout << "R,R,R,R,R" << endl;
          returned = true;
          }
        else
          {
          cout << "S,S,S,S,S" << endl;
          }
        }

      getline(cin, line);

      if (line.compare(0, 4, "EXIT") == 0)
        {
        return (0);
        }
      if (line.compare(0, 8, "END_TURN") != 0)
        {
        cerr << "INVALID END_TURN \"" << line << "\"" << endl;
        }

      stringstream ss(line);
      string item;
      int i = 0;
      while (getline(ss, item, ' '))
        {
        i++;
        if (i > 2 && i - 3 != index)
          {
          int num_to_add = count(item.begin(), item.end(), 'R'); // Add turn to today_returns for each servant that returned
          for (int j = 0; j < num_to_add; j++)
            {
            today_returns.push_back(turn);
            }
          }
        }

      }

    getline(cin, line);

  end_day:

    if (line.compare(0, 4, "EXIT") == 0)
      {
      return (0);
      }
    else if (line.compare(0, 7, "END_DAY") != 0)
      {
      cerr << "INVALID END_DAY \"" << line << "\"" << endl;
      return (-1);
      }

    stringstream ss(line);
    string item;
    int i = 0;
    num_alive = 0;
    while (getline(ss, item, ' '))
      {
      i++;
      if (i > 2 && i - 3 != index)
        {
        num_alive += count(item.begin(), item.end(), 'A');
        }
      else if (i - 3 == index)
        {
        mine_alive = count(item.begin(), item.end(), 'A');
        }
      }

    last_returns = today_returns;
    today_returns.clear();

    }

  return (0);
  }

संकलन करना:

g++ -o Bob.exe Bob.cpp

चलाने के लिए:

./players/Bob/Bob.exe

6

सांख्यिकीविद्, पायथन 3

सांख्यिकीविद् हमेशा साथ काम करते हैं। पहली बारी में, वे शिविर में लौटते हैं जब दो तिहाई उनके विरोधियों ने ऐसा किया है। बाद के मोड़ों पर, वे अन्य सेवकों की आदतों की भविष्यवाणी करने के लिए पिछले घुमावों से एकत्र किए गए डेटा पर भरोसा करते हैं, और अंतिम सुरक्षित क्षण में शिविर में लौटने की कोशिश करते हैं।

कार्यक्रम

# Team of treasure-hunting statisticians
# Run with:
# python3 statisticians.py

num_others = None
running = True
while running:
    msg = input().split()
    msg_type = msg.pop(0)
    if msg_type == "INDEX":
        my_index = int(msg[0])-1
    elif msg_type == "START_DAY":
        day, max_deaths = tuple(map(int, msg[0].split('/')))
    elif msg_type == "START_TURN":
        turn = int(msg[0])
        if day == 1:
            if turn == 1:
                print("S,S,S,S,S")
            elif turn == 30 or num_active <= max_deaths * 4/5:
                print("R,R,R,R,R") # On first day, return when 4/5 of  maximum number of dying servants remain
            else:
                print("S,S,S,S,S")
        elif turn >= 29 or len(expected_servants[turn+1]) <= max(2, max_deaths * 3/4) or len(expected_servants[turn]) <= max(2, max_deaths * 1/4):
            print("R,R,R,R,R") # If many servants are expected to return next turn or someone is sure to die, return to camp
        else:
            print("S,S,S,S,S") # Otherwise, keep going
    elif msg_type == "END_TURN":
        turn = int(msg.pop(0))
        others_moves = [tuple(s.split(',')) for s in msg[:my_index] + msg[my_index+1:]]
        if num_others is None: # End of first turn, initialize variables that depend on number of servants
            num_others = len(others_moves)
            others_history = [{} for i in range(num_others)]
        if day == 1:
            num_active = sum([move.count('S') for move in others_moves])
        for i, moves in enumerate(others_moves): # Log the return habits of other bots
            if turn == 1:
                others_history[i][day] = [0]*5
            for j, move in enumerate(moves):
                if move == "R": # Only safely returned servants are taken into account
                    others_history[i][day][j] = turn
                    if day > 1:
                        for future_turn in range(turn, 30):
                            expected_servants[future_turn].discard((i,j))
    elif msg_type == "END_DAY":
        day = int(msg.pop(0))
        my_statuses = tuple(msg[my_index].split(','))
        others_statuses = [tuple(s.split(',')) for s in msg[:my_index] + msg[my_index+1:]]
        expected_servants = [set() for i in range(30)] # Compute the sets of expected servants for each turn
        for i in range(num_others):
            for j in range(5):
                if others_statuses[i][j] == 'A':
                    turn_sum = 0
                    for day_num in others_history[i]:
                        turn_sum += others_history[i][day_num][j]
                    for turn in range(turn_sum//day):
                        expected_servants[turn].add((i,j))
    elif msg_type == "EXIT":
        running = False

जैसा कि आप देख सकते हैं, मैं बेशर्मी से @ माइक स्वीनी से कार्यक्रम संरचना चुरा रहा हूं।

आदेश

python3 statisticians.py

संपादित करें: घर लौटने के लिए चेक में एक बग फिक्स्ड। उन्हें अब कुछ बेहतर प्रदर्शन करना चाहिए।

EDIT 2: सांख्यिकीविद् पहले की तुलना में अब अधिक स्मार्ट हो गए हैं: वे इस बात पर नज़र रखते हैं कि वर्तमान समय में कौन से सेवक शिविर में वापस आए हैं, और तदनुसार अपनी भविष्यवाणियों को समायोजित करें। इसके अलावा, वे अधिक जोखिम उठाते हैं, शिविर में लौटने पर अधिकतम संख्या में 3/4 मरने वाले नौकर रहते हैं। यह उन्हें शीर्ष पर वापस धकेल देता है (बस मुश्किल से; बॉब बहुत खतरनाक हो गया है)।


5

नशे में, पर्ल ५

थोड़ा बहुत शराब और वे वापस शिविर के लिए अपना रास्ता कभी नहीं मिलेगा।

यह प्रविष्टि मुख्य रूप से एक उदाहरण है, लेकिन भाग लेंगे।

कार्यक्रम

#!/usr/bin/perl
use 5.10.1;
$| = 1; # disable buffering
@actions = qw(S S S S S);

$_ = <>; ~/^INDEX (\d+)/;
$index = $1;

while(<>){
    if(index($_, 'START_TURN') == 0){
        say join(',', @actions);
    }elsif(index($_, 'END_DAY') == 0){ 
        # update actions based on who is alive
        # index 1-indexed; first bot at position 2.
        # this is not actually necessary for Drunkards, as all of Drunkards'
        #  servants will die on day 1 in any case.
        # This check is here simply as an example.
        my @status = split(',',(split(' '))[$index + 1]);
        my $i;
        for($i = 0; $i < 5; ++$i){
            # action is S if alive, N if dead. Servants will never be in camp.
            $actions[$i] = $status[$i] eq 'A' ? 'S' : 'N';
        }
    }elsif(index($_, 'EXIT') == 0){
        exit 0;
    }
}

आदेश

perl ./players/Drunkards/Drunkards.pl

क्या युक्ति को पूरा करने के लिए आपका कोड $status[$i] eq 'A' ? 'S' : 'D';होना चाहिए $status[$i] eq 'A' ? 'S' : 'N';?
लॉजिक नाइट

@MikeSweeney अच्छा कैच। मैं यह तय करना भूल गया कि जब मैंने युक्ति बदली थी जबकि यह चुनौती अभी भी सैंडबॉक्स में थी।
es1024

4

मॉर्निंग बर्ड्स

जल्दी पक्षी कीड़ा पकड़ता है!!!

package players.MorningBirds;

import java.io.*;
import java.util.*;

/*
 * Java 7
 * 
 * Compile with "javac ./players/MorningBirds/MorningBirds.java"
 * Run with "java players.MorningBirds.MorningBirds"
 * 
 * Servants find treasure from morning until noon.
 * At noon they go to bed to prepare for next day.
 * 
 * According to Benjamin Franklin, "Early to bed, early to rise, keeps a 
 *      man healthy, WEALTHY, and wise."
 * 
 * 
 */
public class MorningBirds {

    protected final static String STARTDAY = "START_DAY";

    protected final static String STARTTURN = "START_TURN";

    protected final static String ENDTURN = "END_TURN";

    protected final static String ENDDAY = "END_DAY";

    protected final static String MOVERETURN = "R";

    protected final static String MOVESEARCH = "S";

    protected final static String MOVENOTHING = "N";

    protected final static String RETURNED = "R";

    protected final static String FAILEDRETURN = "r";

    protected final static String SEARCHING = "S";

    protected final static String DEAD = "D";

    protected final static String SLEEPING = "N";

    protected final static String EXIT = "EXIT";

    protected final static String ALIVE = "A";

    protected enum Status{SEARCHING, DEAD, RETURNED}

    protected enum Move{RETURN, SEARCH, NOTHING}

    protected int index;

    protected int day;

    protected int turnNum;

    protected int howManyTeams;

    protected int howManyWillDieTodayAtMost;

    protected int howManyHaveDiedToday;

    protected int howManyEnemyPlayers;

    protected int howManyAliveEnemyPlayers;

    protected int howManyEnemyTeams;

    protected int howManyDeadEnemyPlayers;

    protected int howManyReturnedEnemyPlayers;

    protected int howManySearchingEnemyPlayers;

    protected int howManyTotalPlayers;

    protected int howManyTotalAlivePlayers;

    protected int howManyTotalDeadPlayers;

    protected int howManyTotalReturnedPlayers;

    protected int howManyTotalSearchingPlayers;

    protected int howManyOwnAlivePlayers;

    protected int howManyOwnDeadPlayers;

    protected int howManyOwnReturnedPlayers;

    protected int howManyOwnSearchingPlayers;

    protected Status[] statuses = new Status[5];

    protected Status[][] allStatuses = null;

    protected List<Status[][]> allDayStatuses = null;

    protected List<List<Status[][]>> allTimeStatuses = new ArrayList<>();

    protected BufferedReader in = new BufferedReader(
            new InputStreamReader(System.in));

    public static void main (String args[]) throws Exception{
        new MorningBirds().start();
    }

    public void start() throws Exception{

        index = Integer.parseInt(in.readLine().split("\\s")[1]);
        Arrays.fill(statuses, Status.SEARCHING);

        while(true){
            String[] input = in.readLine().split("\\s");
            if (input[0].equals(ENDTURN) || input[0].equals(ENDDAY)){
                updateStatus(input);
            } else if (input[0].equals(EXIT)){
                return;
            } else if (input[0].equals(STARTDAY)){
                updateDay(input);
            } else if (input[0].equals(STARTTURN)){
                updateTurn(input);
                doTurn(input);
            }

        }

    }

    protected void updateStatus(String[] input){
        if (allStatuses == null && input[0].equals(ENDTURN)){
            allStatuses = new Status[input.length - 2][5];
            for (Status[] enemyStatus : allStatuses){
                Arrays.fill(enemyStatus, Status.SEARCHING);
            }
            howManyTeams = input.length - 2;
            howManyEnemyTeams = input.length - 3;
            howManyTotalPlayers = howManyTeams * 5;
            howManyTotalAlivePlayers = howManyTotalPlayers;
            howManyTotalSearchingPlayers = howManyTotalAlivePlayers;
            howManyAliveEnemyPlayers = howManyTotalPlayers - 5;
            howManyEnemyPlayers = howManyEnemyTeams * 5;
            howManyOwnAlivePlayers = 5;
            howManyOwnSearchingPlayers = 5;
            howManySearchingEnemyPlayers = howManyAliveEnemyPlayers;
        }
        for ( int j = 0; j < howManyTeams; j++){
            String[] stats = input[j + 2].split(",");
            for(int i = 0; i < 5; i++){
                switch (stats[i]){
                    case "R":
                    case "N":
                        if (allStatuses[j][i] != Status.RETURNED){
                            howManyTotalReturnedPlayers++;
                            howManyTotalSearchingPlayers--;
                            if (j == index - 1) {
                                howManyOwnReturnedPlayers++;
                                howManyOwnSearchingPlayers--;
                            } else {
                                howManyReturnedEnemyPlayers++;
                                howManySearchingEnemyPlayers--;
                            }
                        }
                        allStatuses[j][i] = Status.RETURNED;
                        break;
                    case "A":
                    case "S":
                        if (allStatuses[j][i] != Status.SEARCHING){
                            howManyTotalReturnedPlayers--;
                            howManyTotalSearchingPlayers++;
                            if (j == index - 1) {
                                howManyOwnReturnedPlayers--;
                                howManyOwnSearchingPlayers++;
                            } else {
                                howManyReturnedEnemyPlayers--;
                                howManySearchingEnemyPlayers++;
                            }
                        }
                        allStatuses[j][i] = Status.SEARCHING;
                        break;
                    case "r":
                    case "D":
                        if (allStatuses[j][i] != Status.DEAD){
                            howManyTotalAlivePlayers--;
                            howManyTotalDeadPlayers++;
                            howManyHaveDiedToday++;
                            howManyTotalSearchingPlayers--;
                            if (j == index - 1){
                                howManyOwnAlivePlayers--;
                                howManyOwnDeadPlayers++;
                                howManyOwnSearchingPlayers--;
                            } else {
                                howManyAliveEnemyPlayers--;
                                howManyDeadEnemyPlayers++;
                                howManySearchingEnemyPlayers--;
                            }
                        }
                        allStatuses[j][i] = Status.DEAD;
                        break;
                    default:
                        break;
                }
            }
        }
        statuses = allStatuses[index - 1];
        if (input[0].equals(ENDTURN)){
            allDayStatuses.add(allStatuses.clone());
        }
        if (input[0].equals(ENDDAY)){
            Status[][] statusesToAdd = new Status[howManyTeams][5];
            for (int i = 0; i < statusesToAdd.length; i++){
                for (int j = 0; j < statusesToAdd[i].length; j++){
                    if (allStatuses[i][j] == Status.SEARCHING){
                        statusesToAdd[i][j] = Status.RETURNED;
                    } else {
                        statusesToAdd[i][j] = Status.DEAD;
                    }
                }
            }
            while (turnNum <= 30){
                allDayStatuses.add(statusesToAdd.clone());
                turnNum++;
            }
            allTimeStatuses.add(allDayStatuses);
        }
    }

    protected void updateDay(String[] input) throws Exception{
        day = Integer.parseInt(input[1].split("/")[0]);
        howManyWillDieTodayAtMost = Integer.parseInt(input[1].split("/")[1]);
        howManyHaveDiedToday = 0;
        allDayStatuses = new ArrayList<>();
        if (day == 1){
            Arrays.fill(statuses, Status.SEARCHING);
            howManyOwnAlivePlayers = 5;
            howManyOwnSearchingPlayers = 5;
        }
    }

    protected void updateTurn(String[] input){
        turnNum = Integer.parseInt(input[1]);
    }

    protected void doTurn(String[] input){
        Move[] moves = new Move[5];
        for (int i = 0; i < 5; i++){
            if (statuses[i] == Status.DEAD ||
                        statuses[i] == Status.RETURNED) {
                moves[i] = Move.NOTHING;
                continue;
            } else {
                moves[i] = doMove(i);
            }
        }
        String[] outputs = new String[5];
        for (int i = 0; i < 5; i++){
            switch (moves[i]){
                case SEARCH:
                    outputs[i] = MOVESEARCH;
                    break;
                case RETURN:
                    outputs[i] = MOVERETURN;
                    break;
                case NOTHING:
                    outputs[i] = MOVENOTHING;
            }
        }
        String totalOutput = "";
        for(String output : outputs){
            if (totalOutput != ""){
                totalOutput += ",";
            }
            totalOutput += output;
        }
         System.out.println(totalOutput);
    }

    //Implement this method differently for different 
    //strategies. 
    public Move doMove(int playerNumber){
        if (turnNum >= 15){
            return Move.RETURN;
        }
        return Move.SEARCH;
    }

    /**
     * Returns the status of one of your players. 
     * Your players have numbers 1 to 5 inclusive.
     * Throws exception if number is outside range.
     * 
     */
    protected Status getStatus(int player){
        if (player > 5 || player < 1){
            throw new IllegalArgumentException(
                    "getStatus(" + player +") failed.");
        }
        return statuses[player - 1];
    }

    /**
     * Returns the status of a player in a team.
     * Team numbers start with 1 inclusive.
     * Players have numbers 1 to 5 inclusive.
     * Throws exception if argument player is outside range.
     * Throws exception if argument team is less than 1 or is greater
     * than the number of teams.
     * Returns Status.SEARCHING if day == 1 and turnNum == 1 and argument 
     * team >= 1.
     */
    protected Status getStatus(int team, int player){
        if (team < 1 || player < 1 || player > 1 || 
                (team > howManyTeams && day == 1 && turnNum == 1)){
            throw new IllegalArgumentException(
                    "getStatus(" + team + ", " + player + ") failed.");
        }
        if (day == 1 && turnNum == 1 && team >= 1){
            return Status.SEARCHING;
        }
        return allStatuses[team - 1][player - 1];
    }

    /**
     * Returns the status of a player in a team at the end of argument
     * turn.
     * Team numbers start with 1 inclusive.
     * Players have numbers 1 to 5 inclusive.
     * Turns have numbers 0 to 30 inclusive.
     * Status at turn 0 is equal to status at start of turn 1.
     * Throws exception if argument turn hasn't happened yet.
     * Throws exception if argument player is outside range.
     * Throws exception if argument team is less than 1 or is greater
     * than the number of teams.
     */
    protected Status getStatus(int turn, int team, int player){
        if (turn == 0){
            if (day == 1){
                return Status.SEARCHING;
            } else {
                return getStatus(day - 1, 30, team, player);
            }
        }
        if (turnNum <= turn || turn < 0|| player > 5 || player < 1 ||
                team < 1 || team > howManyTeams){
            throw new IllegalArgumentException("getStatus(" + turn + 
                    ", " + team + ", " + player + ") failed.");
        }
        return allDayStatuses.get(turn - 1)[team - 1][player - 1];
    }

    /**
     * Returns the status of a player in a team at the end of argument
     * turn on the day of argument day.
     * Team numbers start with 1 inclusive.
     * Players have numbers 1 to 5 inclusive.
     * Turns have numbers 0 to 30 inclusive.
     * Days have numbers 1 inclusive and up.
     * Status at turn 0 is equal to status at start of turn 1.
     * Throws exception if argument day hasn't ended yet or is less 
     * than one.
     * Throws exception if argument turn is out of range.
     * Throws exception if argument player is outside range.
     * Throws exception if argument team is less than 1 or is greater
     * than the number of teams.
     */
    protected Status getStatus(int day, int turn, int team, int player){
        if (turn == 0){
            if (day == 1){
                return Status.SEARCHING;
            } else {
                return getStatus(day - 1, 30, team, player);
            }
        }
        if (this.day <= day || day < 1 || turn > 30 || turn < 0 || 
                player > 5 || player < 1 ||
                team < 1 || team > howManyTeams){
            throw new IllegalArgumentException("getStatus(" + day + ", "
                    + turn + ", " + team + ", " + player + ") failed.");
        }
        return allTimeStatuses.get(day - 1).get(turn - 1)[team - 1][player - 1];
    }

}

संपादित करें: इसे बनाया ताकि कोई भी इसे आसानी से अपने अधीन कर सके। बस doMove(int playerNumber)अपने खुद के बॉट के लिए फिर से परिभाषित करें। मैंने कई सहायक फ़ील्ड और विधियाँ जोड़ी हैं। मैंने बड़े पैमाने पर इसका परीक्षण किया है। यह पिछले सिमुलेशन से स्थिति को नहीं बचाता है। यदि कोई समस्या हो तो कृपया मुझे बताएं।

संकलन: javac ./players/MorningBirds/MorningBirds.java

साथ दौड़ो: java players.MorningBirds.MorningBirds


क्या यह ठीक होगा यदि मैंने विधियों और चरों की रक्षा की और बाद में चुनौती के लिए इसे उपवर्ग बना दिया?
TheNumberOne

यदि आवश्यक हो तो कई स्रोत फ़ाइलों का उपयोग करने के लिए स्वतंत्र महसूस करें, या अन्य प्रविष्टियों से कोड का पुन: उपयोग करें, जब तक कि प्रविष्टियां एक साथ काम नहीं कर रही हैं।
es1024

@ es1024 प्रयोग करने में मैंने देखा कि एक बॉट मर जाता है अगर वह दिन भर बारी बारी से कुछ नहीं करता है। क्या यह इरादा है?
TheNumberOne

एक बॉट जो Rकिसी भी दिन कभी नहीं लौटता ( ) उस दिन हमेशा मर जाएगा।
es1024

यदि मैं खिलाड़ी SlowReturners और Randomizers को जोड़ता हूं तो नियंत्रक अप्रतिसादी हो जाता है। नोट: क्षमा करें, मैं यहाँ टिप्पणियाँ पोस्ट कर रहा हूँ। अन्यत्र पोस्ट करने के लिए मेरे पास आवश्यक प्रतिष्ठा नहीं है।
TheNumberOne

3

रैंडमाइज़र - रूबी

बस आँकड़े संचालित बॉट को गड़बड़ करने के लिए, रैंडमाइज़र काफी अप्रत्याशित हैं। वे सभी एक बार में, दूसरों को फँसाने के प्रयास में एक यादृच्छिक मोड़ पर वापस लौटते हैं।

(अन्य खिलाड़ियों से प्रभावित नहीं।)

def min(a,b);(a<b)?a:b;end
x=""
r=0
while x != "EXIT"
  x=gets.chomp
  if x =~ /^START_DAY/
    r = min(rand(30),rand(30))
  end
  if x =~ /^START_TURN (\d*)/
    puts ($1.to_i>r)?'R,R,R,R,R':'S,S,S,S,S'
  end
end

2

घूमते हुए मुर्गे, अजगर 2

यह एक साधारण अजगर बॉट है जो एक पूर्व निर्धारित "गॉबक" समय तक पहुंचने तक नौकरों को भेजता है, फिर वे शिविर में प्रवेश करने और अगले दिन तक रहने की कोशिश करते हैं।

यह अधिक जटिल बॉट्स के लिए एक बुनियादी ढांचा भी है जिसका उपयोग अन्य लोग करना चाहते हैं। हालांकि, यह जज इंजन के साथ अप्रयुक्त है, इसलिए मुझे बताएं कि क्या मैंने कोई त्रुटि की है।

कार्यक्रम

import sys
from random import randint, choice
team = range(5)

while True:
    inp = sys.stdin.readline().split()
    cmd = inp.pop(0)
    if cmd == 'INDEX':
        teamnum = int(inp[0]) - 1   # using zero based indexing
    elif cmd == 'START_DAY':
        daynum, deadnum = [int(v) for v in inp[0].split('/')]
        # Set up strategy for the day:
        goback = [randint(5,25) for i in team]
    elif cmd == 'START_TURN':
        turn = int(inp[0])
        # Output actions [R]eturn, [S]earch, [N]othing here:
        actions = ['S' if turn < goback[i] else 'R' for i in team]
        sys.stdout.write( (','.join(actions)) + '\n' )
        sys.stdout.flush()
    elif cmd == 'END_TURN':
        endturn = int(inp.pop(0))
        status = [v.split(',') for v in inp]  # R,r,S,D,N
        # [R]eturned, [r]ejected, [S]earching, [D]ead, [N]othing
        mystatus = status[teamnum]
    elif cmd == 'END_DAY':
        endturn = int(inp.pop(0))
        alive = [v.split(',') for v in inp]  # [A]live or [D]ead
        myalive = alive[teamnum]
    elif cmd == 'EXIT':
        sys.exit(0)

आदेश

python WanderingFools.py

संपादित करें: नियम स्पष्टीकरण के बाद कोड बदलने की कार्रवाई।


2

विकसित

मैंने इस बॉट को बनाने के लिए जेनेटिक प्रोग्रामिंग (JGAP के माध्यम से) का इस्तेमाल किया। यह एक सरल उत्तर के साथ आया था जो अन्य सभी (मुश्किल से) धड़कता है।

package players.Evolved;

import players.MorningBirds.*;
import java.util.*;

public class Evolved extends MorningBirds{

    List<Integer> scrambled = new ArrayList<>();

    public static void main(String[] args) throws Exception{
        new Evolved().start();
    }

    public Evolved() throws Exception{
        super();
    }

    @Override
    public MorningBirds.Move doMove(int playerNum){
        if (!(howManyTotalSearchingPlayers < (turnNum - getScrambled(index)))){
            return Move.SEARCH;
        } else {
            return Move.RETURN;
        }
    }

    @Override
    protected void updateStatus(String[] input){
        super.updateStatus(input);
        if (input[0].equals(ENDTURN) && (Integer.parseInt(input[1]) == 1)){
            for (int i = 1; i <= howManyTeams; i++){
                scrambled.add(i);
            }
            Collections.shuffle(scrambled);
        }
    } 

    public int getScrambled(int in){
        if (in > scrambled.size() || in < 1 ){
            return in;
        }
        return scrambled.get(in - 1);
    }
}

संकलन: javac players/Evolved/Evolved.java

साथ दौड़ो: java players.Evolved.Evolved

संपादित करें: Grrr ... बॉब ने मुझे गड़बड़ कर दिया !!!

संपादित करें: हाँ !!! बॉब, एक बुरा प्लेग से मारा गया !!!


1

SlowReturners - रूबी

हर 5 बारी में एक नौकर को वापस भेजती है।

x=""
while x != "EXIT"
  x=gets.chomp
  if x =~ /^START_TURN (\d*)/
    puts (1..5).map{|i|(i<=$1.to_i/5)?"R":"S"}.join(",")
  end
end

1

प्लेग

प्लेग एक बीमारी है। यह तर्कसंगत नहीं है। यह अनुमानित है। रोग खजाना इकट्ठा नहीं कर सकते हैं, न ही वे खजाने की देखभाल करते हैं। प्लेग अन्य खिलाड़ियों को बीमार बनाता है। बुद्धिमान घर में रहते हैं और खजाने के बारे में भूल जाते हैं। मूर्ख व्यक्ति हमेशा मूर्ख होते हैं और उन्हें कभी बहुत खजाना नहीं मिलेगा। विकसित (सौभाग्य से) प्लेग के लिए प्रतिरक्षा है। वह बुद्धिमान भी है। वह जाता है और खजाना इकट्ठा करता है, और मरता नहीं है।

package players.Plague;

import players.MorningBirds.MorningBirds;

public class Plague extends MorningBirds{

    public static void main(String[] args) throws Exception{
        new Plague().start();
    }

    public Plague() throws Exception{
        super();
    }

    @Override
    public MorningBirds.Move doMove(int playerNum){
        if (day > howManyTotalDeadPlayers){
            return Move.SEARCH;
        } else {
            return Move.RETURN;
        }
    }
}

संकलन: javac players/Plague/Plague.java

साथ दौड़ो: java players.Plague.Plague

बॉब और सांख्यिकीविद् अब प्लेग के प्रतिरोधी हैं।


हम्म ... जब मैं इस बॉट को चलाता हूं तो यह हमेशा पहले दिन मर जाती है ...

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