කේව්මන් ඩුවල්ස් (හෝ: මම ඔබට තියුණු පොල්ලකින් පහර දෙමි)


152

ගුහා මිනිසාට පිස්සු. අනෙක් ගුහා මිනිසා සැරයටිය ගන්න නමුත් සැරයටිය මට විය. ගුහා මිනිසාගේ සටන !


විස්තර

ගුහා මිනිසාට වෙනත් ගුහා මිනිසාට පිහියෙන් ඇනීමට තියුණු පොල්ලක් අවශ්‍ය වේ. අනෙක් ගුහා මිනිසා ද තියුණු පොල්ලකින් පිහියෙන් ඇනීමට උත්සාහ කරයි. ගුහා මිනිසාට සැරයටිය මුවහත් කර ගැනීමට, සැරයටියෙන් ඇනීමට හෝ කුකුළා අවහිර කිරීමට හැකිය.

ගුහා මිනිසා වෙනත් ගුහා මිනිසාට තියුණු පොල්ලකින් පහර දුන්නොත්, අනෙක් ගුහා මිනිසා පලා ගොස් මා ජයග්‍රහණය කරයි. නමුත් අනෙක් ගුහා මිනිසා මා දෙස බලන විට අවහිර කරන්නේ නම්, මගේ සැරයටිය නොපැහැදිලි වී නැවත මුවහත් කර ගත යුතුය.

ගුහා කම්මැලි. එසේම, ගුහා මිනිසා ගොළු ය. ගුහා මිනිසා කුමක් කළ යුතු දැයි නොදනී. එබැවින් ගුහා මිනිසාට කුමක් කළ යුතු දැයි පැවසීමට ගුහා මිනිසාට විසිතුරු තාක්ෂණික පරිගණක වැඩසටහනක් අවශ්‍ය වේ.

ආදානය

ඔබේ වැඩසටහනේ ආදානය සිදුවී ඇති සිදුවීම්වල ඉතිහාසයක් වනු ඇත, එහිදී Sමුවහත් කිරීම (එනම් ගුහා මිනිසා තම සැරයටිය මුවහත් කර ගැනීම), Pසිදුරු කිරීම සඳහා පෙනී සිටීම සහ Bඅවහිර කිරීම නියෝජනය කරයි. ආදානය දෙපාර්ශවයේම (ඔබ සහ ප්‍රතිවාදියාගේ) ඉතිහාසයක් වනු ඇත, එබැවින් ඔබේ සහ ප්‍රතිවාදියාගේ චලනයන් කොමාවකින් වෙන් කරනු ලැබේ ( ,).

උදාහරණ ආදානය:

SPB,SBB

මෙයින් අදහස් කරන්නේ ක්‍රීඩකයා ඔහුගේ / ඇයගේ සැරයටිය මුවහත් කර, පසුව සිදුරු කර, පසුව අවහිර කර, ප්‍රතිවාදියා මුවහත් කර, පසුව අවහිර කර, නැවත අවහිර කළ බවයි.

1 වන වාරයේ ඔබට කිසිදු ආදානයක් නොලැබෙනු ඇත.

ප්‍රතිදානය

ප්‍රතිදානය ආදානයට බෙහෙවින් සමාන ය (ගුහා මිනිසා ඉතා දක්ෂ නොවන නිසා). ඔබේ වැඩසටහන Sමුවහත් කිරීමට, Pසිදුරු කිරීමට සහ Bඅවහිර කිරීමට ප්‍රතිදානය කළ යුතුය . ප්‍රතිදානයේ පළමු අක්‍ෂරය පමණක් සැලකිල්ලට ගනු ලබන අතර වෙනත් ඕනෑම ආදානයක් B(වාරණ) විධානයක් ලෙස සලකනු ලැබේ .

  • S: මුවහත් කරන්න

    මුවහත් කරන විට, ගුහා මිනිසාගේ සැරයටියේ තියුණු බව 1 කින් ඉහළ යන අතර සැරයටියට අමතර සිදුර 1 ක් ලැබේ. සෑම සිදුරකින්ම සැරයටියේ තියුණු බව 1 කින් අඩු කරයි, සහ සැරයටියේ තියුණු බව 0 නම්, එය සිදුරු කිරීමට නොහැකි තරම් අඳුරු ය. තියුණුබව 0 න් ආරම්භ වේ. තියුණු බව 5 ට වැඩි නම්, සැරයටිය කඩුවකි! (පහත බලන්න.)

    ඔබ මුවහත් කරද්දී ප්‍රතිවාදියා විදිනවා නම් (ඔවුන්ට තියුණු බවක් ඇත> 0), ප්‍රතිවාදියා ජය ගනී!

  • P: විදිනවා

    සිදුරු කරන විට, ගුහා මිනිසාගේ සැරයටියේ තියුණු බව 1 කින් අඩු වන අතර ඔබ ඔබේ ප්‍රතිවාදියාට පහර දෙයි! ඔබේ ප්‍රතිවාදියා මුවහත් කරන්නේ නම්, ඔබ දිනයි! ප්‍රතිවාදියා විදිනවා නම්, ඔබේ සැරයටිය ඔබේ ප්‍රතිවාදියාගේ සැරයටියට පහර දෙන අතර ඔවුන් දෙදෙනාම අඳුරු වේ (1 “තියුණු ඒකකය” මගින්). ප්‍රතිවාදියා අවහිර කරන්නේ නම්, ඔබේ සැරයටිය අඳුරු වීම හැර වෙන කිසිවක් සිදු නොවේ.

    ඔබේ සැරයටියේ තියුණුබව 5 හෝ ඊට වැඩි නම් ඔබ විදිනවා නම්, ඔබේ සැරයටිය කඩුවක් බවට පත්වන අතර ඔබ සැමවිටම ජය ගනී! (ඔබේ ප්‍රතිවාදියාට කඩුවක් ද තෝරාගෙන Pතිබේ නම් මිස, ඔවුන් දෙදෙනාම අඳුරු වන අතර, ඒවායේ තියුණුබව 5 ට වඩා අඩු වුවහොත් කූරු වෙත ආපසු යා හැකිය.)

    ඔබට 0 ක තියුණු බවක් පෙන්විය නොහැක. ඔබ එසේ කළහොත් කිසිවක් සිදු නොවේ.

  • B: අවහිර කරන්න

    ඔබ අවහිර කළ විට, ඔබේ ප්‍රතිවාදියා විදින විට කිසිවක් සිදු නොවේ. ඔබේ ප්‍රතිවාදියා විදිනවා නම්, බ්ලොක් කිසිවක් නොකරයි.

    අවහිර කිරීම කඩුවකින් ආරක්ෂා නොවේ, ඔබ සතුව එකක් තිබුණත්!

නීති සහ අවහිරතා

අමතර නීති:

  • ඔබගේ වැඩසටහන එහි ගොනු කියවිය හැකි හා ලිවීම් ඔබ දත්ත සුරැකීමට අවශ්ය නම් ෆෝල්ඩරය (කිසිදු සොරකම්!), නමුත් ඔබට එය ප්රවේශ දෙයක් පිටත (සහ ගල්ලෙන් තුළ පාළුකරයේ අන්තර්ජාල සම්බන්ධය ඇති නොවන) කළ නොහැක.
    • ලිපිගොනු පිළිබඳ වැදගත් සටහන : ඔබ ගොනු සුරකිනවා නම්, ඒවා නාමාවලියෙහි සුරැකීමට මතක තබා ගන්න players/YourBotsName/somefile.foo! ඔබගේ වැඩසටහන සඳහා දැනට වැඩ කරන නාමාවලිය ඔබේ වැඩසටහනේ නොවනු ඇත!
  • ගුහා මිනිසුන් සාධාරණ ය: එක් වැඩසටහනකට තවත් වැඩසටහනක් සඳහා කේතයක් තිබිය නොහැකි අතර වැඩසටහන් එකිනෙකාට උදව් කළ නොහැක. (ඔබට බහුවිධ වැඩසටහන් තිබිය හැකි නමුත් ඔවුන්ට එකිනෙකා සමඟ කිසිම ආකාරයකින් කටයුතු කළ නොහැක.)
  • ගුහා විනිසුරුවරයා ඉවසිලිවන්ත නැත. ජයග්‍රාහකයෙකු තීරණය කිරීම සඳහා ගුහා භටයින් හැරීම් 100 කට වඩා ගතහොත්, විනිසුරුවරයා කම්මැලි වන අතර ගුහාකරුවන් දෙදෙනාම අහිමි වේ.

ඔබේ වැඩසටහන රීතියක් කඩ කළහොත් හෝ පිරිවිතරයන් අනුගමනය නොකරන්නේ නම්, වැඩසටහන නුසුදුස්සකු වේ, ඉවත් කරනු ලැබේ playerlist.txt, සහ සියලු ඩුවල්ස් මුල සිටම නැවත ආරම්භ වේ. ඔබේ වැඩසටහන නුසුදුස්සකු නම්, ගුහා නායකයා (මම!) ඔබේ වැඩසටහනේ සටහන ගැන අදහස් දක්වමින් එයට හේතුව පැහැදිලි කරයි. ඔබ කිසිදු නීති රීති කඩ නොකරන්නේ නම්, ඔබේ වැඩසටහන ප්‍රමුඛ පුවරුවට එක් කරනු ඇත. .

ඔබගේ ලිපියේ, කරුණාකර ඇතුළත් කරන්න:

  • නමක්.
  • ඔබේ වැඩසටහන (උදා. ක්රියාත්මක කිරීමට විධාන java MyBot.java, ruby MyBot.rb, python3 MyBot.py, ආදිය).
    • සටහන: ආදාන විධාන රේඛා තර්කයක් ලෙස මේ සඳහා එකතු වේ.
    • ගුහා මිනිසුන් උබුන්ටු 14.04 භාවිතා කරයි, එබැවින් ඔබේ කේතය (නිදහසේ) ක්‍රියාත්මක වන බවට වග බලා ගන්න.
  • ඔබ තෝරාගත් භාෂාවේ විවිධ අනුවාදයන් මත ඔබේ කේතය වෙනස් ලෙස ක්‍රියා කරන්නේ නම් අනුවාද අංකයකි.
  • ඔබේ කේතය (පැහැදිලිවම).
  • අවශ්‍ය නම් කේතය සම්පාදනය කරන්නේ කෙසේද?

පාලක කේතය / පරීක්ෂා කිරීම, උදාහරණ බොට්

ගුහා නායකයා C ++ හි පාලන කේතය ලියා එය ගිතුබ් ගබඩාවක පළ කළේය . ඔබට එහි වැඩසටහන ක්‍රියාත්මක කර පරීක්ෂා කළ හැකිය.

ඉතා, ඉතා සරල වැඩසටහන (1 රේඛාව!) ද ඇත පහත පිළිතුරු පල .

ලකුණු කිරීම සහ ප්‍රමුඛ පුවරුව

ලකුණු කිරීම පහසුය. කුමන ගුහා මිනිසා ජයග්‍රහණය කළත් ඔහුට කරුණක් ලැබේ. අනෙක් සෑම ගුහා මිනිසෙකුටම එරෙහිව ඩුවල් 3 කට පසුව වැඩිම ලකුණු ලබාගත් ගුහා මිනිසා නව ගුහා නායකයා බවට පත්වේ!

150     Watson
147     SpeculativeSylwester
146     Gruntt
141     BashMagnon
126     ChargerMan
125     PrisonRules
124     ViceLeader
122     MultiMarkov
122     CaveDoctor
120     RegExMan
120     Hodor
117     FancyTechnoAlgorithm
116     Semipatient
113     Watcher
108     BobCaves
105     MinimaxMan
104     Oracle
102     MaybeMarkov
97      Nash
95      Sicillian
95      Feint
95      Basilisk
94      SharpMan
93      Darwin
91      Nigel
91      JavaMan
88      Entertainer
88      CarefulBot
85      CaveMonkey
84      SSBBP
82      SirPokealot
79      MasterPoker
77      Unpredictable
76      IllogicalCaveman
75      SharpenBlockPoke
75      HuddleWolfWithStick
72      WoodenShield
68      PokeBackBot
68      PatientBlacksmith
66      PatientWolf
58      MonteCarloMan
58      BlindFury
56      BinaryCaveman
55      PokeBot
55      CavekidBlocks
53      Swordmaster
53      Blocker
52      NakedEarlyNerd
52      ModestCaveman
50      LatePokeBot
40      Trickster
39      SwordLover
38      ForeignCaveman
36      Swordsmith *
28      Touche
27      WantASword
27      FoolMeOnce
24      PeriodicalCavemanCicada
11      Aichmophobic

(මෙම ප්‍රමුඛ පුවරුව ස්වයංක්‍රීයව ජනනය කරන ලදි)

ක්‍රීඩකයන් *යම් අවස්ථාවක දී යම් ආකාරයක දෝෂයක් හෝ ව්‍යතිරේකයක් විසි කර ඇත; මෙම ක්‍රීඩකයන්ට ඔවුන්ගේ තනතුරු පිළිබඳව අදහස් දැක්වීමක් ද ඇත.

කිසියම් හේතුවක් නිසා එම පරීක්ෂණ ඇතුළත් කළ නොහැකි වූ ක්රීඩකයන් (මෙම ක්රීඩකයන් ප්රශ්නය පැහැදිලි ඔවුන්ගේ තනතුරු පිළිබඳ අදහසක් ඇත): Monkey, Elephant, FacileFibonacci, StudiousSylwester.

අවසන් වරට යාවත්කාලීන කළේ: අගෝස්තු 3 00:15 (යූටීසී).


මිනිමැක්ස් උපායමාර්ගය සොයා ගැනීමට කිසිවෙකු තවමත් උත්සාහ කර නොමැති බව මට පුදුමයි. එය පැහැදිලිවම කළ යුතු දෙයක් ලෙස පෙනේ.
user2357112 මොනිකා

23 user2357112 මිනිමැක්ස් මෙහි වැඩිදියුණු කිරීමක් යැයි මම නොසිතමි. මම කිව්වේ, ඔබට මිනිමැක්ස් ක්‍රියාත්මක කිරීමක් සැලසුම් කළ හැකිය, නමුත් තර්කනය ඉතා සරල බැවින්, එකම නිශ්චිත හැසිරීම සීමිත රාජ්‍ය යන්ත්‍රයකින් ප්‍රකාශ කළ හැකිය. . අවහිර කිරීමට යනාදිය)
හඩ්ල්වුල්ෆ්

3
බොහෝ ඇතුළත් කිරීම් ඒවායේ ගණනය කිරීම්වල negative ණාත්මක තියුණු බවක් ලබා දෙන බව පෙනේ. ලිඛිත නීති රීති වලට අනුව ඔබ තියුණු ලෙස ශුන්‍ය වන විට කිසිවක් සිදු නොවේ. එම “කිසිවක්” යන්නෙන් අදහස් කරන්නේ ඔබේ තියුණුබව අඩු වීම වෙනුවට ශුන්‍යව පවතින බවයි?
ස්පාර්

6
මෙය මෙහි තිබිය යුතුය: dresdencodak.com/comics/2009-09-22-caveman_science_fiction.jpg සමහර විට එය පරිකල්පනය ඉදිරියට ගෙන යනු ඇත. :)
Evi1M4chine

2
මෙය තවමත් විවෘතද? මිනිසුන් නව ඉදිරිපත් කිරීම් එකතු කරන බව මට පෙනේ, නමුත් ප්‍රමුඛ පුවරුව යාවත්කාලීන වන බවක් මට නොපෙනේ.
ASCIIThenANSI

Answers:


35

ඩාවින් - සී

කෙසේ වෙතත් උපාය අවශ්‍ය වන්නේ කාටද? ගුහා භටයන් කණ්ඩායමක් එකිනෙකා වෙත ගොස් ස්වාභාවික වරණයකට ඉතිරි දේ කිරීමට ඉඩ දෙන්න!


ගුහා මිනිසාගේ ප්‍රාථමික මොළය සඳහා අපි ඉතා සරල ආකෘතියක් භාවිතා කරමු: එයට මතකයක් නොමැති අතර ඔහුගේ සහ ඔහුගේ ප්‍රතිවාදියාගේ සැරයටියේ තියුණු බව පමණක් සැලකිල්ලට ගනී. ඒවා කිසියම් සීමිත අනුපිළිවෙලක ද්විමය බහුපදයක් සඳහා විචල්‍යයන් ලෙස භාවිතා කරයි. සෑම ක්‍රියාවකටම (අවහිර කිරීම, මුවහත් කිරීම සහ සිදුරු කිරීම) සම්බන්ධිත බහුපදයක් ඇති අතර එහි ප්‍රති result ලය මෙම ක්‍රියාව තෝරා ගැනීමේ සාපේක්ෂ සම්භාවිතාව තීරණය කරයි. එය සතුව ඇත්තේ එපමණකි --- අහඹු සංගුණක කිහිපයකින් ආරම්භ කර ක්‍රියාකාරී ලෙස ප්‍රශස්ත කරන්න.

බොට්:

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* magic numbers */
#define SWORD_SHARPNESS 5
#define PROGRAM_DIM 4 /* polynomial order + 1 */
#define DEFAULT_FILENAME "players/Darwin/program"

typedef double real;
typedef real program[PROGRAM_DIM][PROGRAM_DIM];
typedef program caveman_brain[3];

typedef char action; /* S, B or P */
/* encodes a pair of actions */
#define ACTION_PAIR(a1, a2) (((int)(a1) << (sizeof(action) * 8)) | (a2))

real eval_program(const program p, double x, double y) {
    real v = 0;
    int i, j;

    for (i = 0; i < PROGRAM_DIM; ++i) {
        real w = 0;
        for (j = 0; j < PROGRAM_DIM; ++j)
            w = x * w + p[i][j];
        v = y * v + w;
    }

    if (v < 0)
        v = 0;
    return v;
}
void read_program(FILE* f, program p) {
    int i, j;
    for (i = 0; i < PROGRAM_DIM; ++i) {
        for (j = 0; j < PROGRAM_DIM; ++j) {
            double v;
            fscanf(f, "%lg", &v);
            p[i][j] = v;
        }
    }
}

int blunt(int* s) {
    int temp = *s;
    if (temp)
        --*s;
    return temp;
}
void sharpen(int* s) { ++*s; }
/* takes two sharpness/action pairs and updates the sharpness accordingly.
 * returns negative value if first caveman wins, positive value if second
 * caveman wins and 0 otherwise. */
int act(int* s1, action a1, int* s2, action a2) {
    switch (ACTION_PAIR(a1, a2)) {
        case ACTION_PAIR('B', 'B'): return 0;
        case ACTION_PAIR('B', 'S'): sharpen(s2); return 0;
        case ACTION_PAIR('B', 'P'): return blunt(s2) >= SWORD_SHARPNESS ? 1 :
                                                                          0;
        case ACTION_PAIR('S', 'B'): sharpen(s1); return 0;
        case ACTION_PAIR('S', 'S'): sharpen(s1); sharpen(s2); return 0;
        case ACTION_PAIR('S', 'P'): sharpen(s1); return *s2 > 0 ? 1 : 0;
        case ACTION_PAIR('P', 'B'): return blunt(s1) >= SWORD_SHARPNESS ? -1 :
                                                                          0;
        case ACTION_PAIR('P', 'S'): sharpen(s2); return *s1 > 0 ? -1 : 0;
        case ACTION_PAIR('P', 'P'): {
            int t1 = blunt(s1), t2 = blunt(s2);
            if (t1 >= SWORD_SHARPNESS && t2 < SWORD_SHARPNESS)
                return -1;
            else if (t2 >= SWORD_SHARPNESS && t1 < SWORD_SHARPNESS)
                return 1;
            else
                return 0;
        }
    }
}
/* processes a pair of strings of actions */
int str_act(int* s1, const char* a1, int* s2, const char* a2) {
    for (; *a1 && *a2; ++a1, ++a2) {
        int winner = act(s1, *a1, s2, *a2);
        if (winner)
            return winner;
    }
    return 0;
}

double frandom() { return (double)rand() / RAND_MAX; }

/* chooses an action based on self and opponent's sharpness */
action choose_action(const caveman_brain b, int s1, int s2) {
    double v[3];
    double sum = 0;
    double r;
    int i;
    for (i = 0; i < 3; ++i) {
        v[i] = eval_program(b[i], s1, s2);
        sum += v[i];
    }
    r = frandom() * sum;
    if (r <= v[0])
        return 'B';
    else if (r <= v[0] + v[1])
        return 'S';
    else
        return 'P';
}

/* portable tick-count for random seed */
#ifdef _WIN32
#include <Windows.h>
unsigned int tick_count() { return GetTickCount(); }
#else
#include <sys/time.h>
unsigned int tick_count() {
    struct timeval t;
    gettimeofday(&t, NULL);
    return 1000 * t.tv_sec + t.tv_usec / 1000;
}
#endif

int main(int argc, const char* argv[]) {
    const char* filename = DEFAULT_FILENAME;
    const char *a1, *a2;
    FILE* f;
    caveman_brain b;
    int s1 = 0, s2 = 0;
    int i;

    srand(tick_count()); rand();

    a1 = argc > 1 ? argv[1] : "";
    if (*a1) {
        a2 = strchr(a1, ',');
        if (a2 == NULL) {
            printf("invalid input!\n");
            return 1;
        }
        ++a2;
    } else
        a2 = a1;

    if (argc > 2)
        filename = argv[2];

    f = fopen(filename, "r");
    if (f == NULL) {
        printf("failed to open `%s'\n", filename);
        return 1;
    }
    for (i = 0; i < 3; ++i)
        read_program(f, b[i]);
    fclose(f);

    str_act(&s1, a1, &s2, a2);
    printf("%c\n", choose_action(b, s1, s2));

    return 0;
}

සමඟ සම්පාදනය කරන්න : gcc darwin.c -odarwin -w -O3. සමඟ ධාවනය කරන්න : ./darwin <history>.

ඩිරෙක්ටරියේ නම් programකර ඇති ගොනුවකින් බොට් සංගුණක කියවයි players/Darwin(වෙනත් ගොනුවක් දෙවන විධාන රේඛා තර්කයක් ලෙස දැක්විය හැක). මෙම වැඩසටහන හොඳින් ක්‍රියාත්මක වන බව පෙනේ:

0.286736 0.381578 -0.128122 1.33933 
0.723126 0.380574 1.21659 -0.9734 
0.924371 0.998632 -0.0951554 0.744323 
-0.113888 -0.321772 -0.260496 -0.136341 

0.280292 -0.699782 -0.246245 1.27435 
-1.24563 -0.959822 -0.745656 0.0347998 
-0.917928 -0.384105 0.319008 -0.70434 
0.484375 0.802138 0.0967234 0.638466 

0.406679 0.597322 1.39409 0.902353 
-0.735946 0.742589 0.955567 0.643268 
-0.503946 0.446167 1.002 0.328205 
0.26037 0.113346 0.0517265 -0.223298 

ලෙස සුරකින්න players/Darwin/program.

පහත දැක්වෙන්නේ programබොට් භාවිතා කළ හැකි ගොනු ජනනය කරන වැඩසටහනකි (ඔබ programඉහත ගොනුව භාවිතා කරන්නේ නම් සම්පාදනය කළ යුතු නොවේ ):

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* magic numbers */
#define SWORD_SHARPNESS 5
#define MAX_TURN_COUNT 100
#define PROGRAM_DIM 4 /* polynomial order + 1 */
#define CAVEMAN_COUNT 500
#define GENERATION_COUNT 12
#define DUEL_COUNT 8
#define ERROR_BACKOFF 0.5
#define DEFAULT_FILENAME "players/Darwin/program"

typedef double real;
typedef real program[PROGRAM_DIM][PROGRAM_DIM];
typedef program caveman_brain[3];

typedef char action; /* S, B or P */
/* encodes a pair of actions */
#define ACTION_PAIR(a1, a2) (((int)(a1) << (sizeof(action) * 8)) | (a2))

real eval_program(const program p, double x, double y) {
    real v = 0;
    int i, j;

    for (i = 0; i < PROGRAM_DIM; ++i) {
        real w = 0;
        for (j = 0; j < PROGRAM_DIM; ++j)
            w = x * w + p[i][j];
        v = y * v + w;
    }

    if (v < 0)
        v = 0;
    return v;
}
void write_program(FILE* f, const program p) {
    int i, j;
    for (i = 0; i < PROGRAM_DIM; ++i) {
        for (j = 0; j < PROGRAM_DIM; ++j)
            fprintf(f, "%g ", p[i][j]);
        fprintf(f, "\n");
    }
    fprintf(f, "\n");
}

int blunt(int* s) {
    int temp = *s;
    if (temp)
        --*s;
    return temp;
}
void sharpen(int* s) { ++*s; }
/* takes two sharpness/action pairs and updates the sharpness accordingly.
 * returns negative value if first caveman wins, positive value if second
 * caveman wins and 0 otherwise. */
int act(int* s1, action a1, int* s2, action a2) {
    switch (ACTION_PAIR(a1, a2)) {
        case ACTION_PAIR('B', 'B'): return 0;
        case ACTION_PAIR('B', 'S'): sharpen(s2); return 0;
        case ACTION_PAIR('B', 'P'): return blunt(s2) >= SWORD_SHARPNESS ? 1 :
                                                                          0;
        case ACTION_PAIR('S', 'B'): sharpen(s1); return 0;
        case ACTION_PAIR('S', 'S'): sharpen(s1); sharpen(s2); return 0;
        case ACTION_PAIR('S', 'P'): sharpen(s1); return *s2 > 0 ? 1 : 0;
        case ACTION_PAIR('P', 'B'): return blunt(s1) >= SWORD_SHARPNESS ? -1 :
                                                                          0;
        case ACTION_PAIR('P', 'S'): sharpen(s2); return *s1 > 0 ? -1 : 0;
        case ACTION_PAIR('P', 'P'): {
            int t1 = blunt(s1), t2 = blunt(s2);
            if (t1 >= SWORD_SHARPNESS && t2 < SWORD_SHARPNESS)
                return -1;
            else if (t2 >= SWORD_SHARPNESS && t1 < SWORD_SHARPNESS)
                return 1;
            else
                return 0;
        }
    }
}
/* processes a pair of strings of actions */
int str_act(int* s1, const char* a1, int* s2, const char* a2) {
    for (; *a1 && *a2; ++a1, ++a2) {
        int winner = act(s1, *a1, s2, *a2);
        if (winner)
            return winner;
    }
    return 0;
}

double frandom() { return (double)rand() / RAND_MAX; }
double firandom() { return 2.0 * rand() / RAND_MAX - 1.0; }

/* chooses an action based on self and opponent's sharpness */
action choose_action(const caveman_brain b, int s1, int s2) {
    double v[3];
    double sum = 0;
    double r;
    int i;
    for (i = 0; i < 3; ++i) {
        v[i] = eval_program(b[i], s1, s2);
        sum += v[i];
    }
    r = frandom() * sum;
    if (r <= v[0])
        return 'B';
    else if (r <= v[0] + v[1])
        return 'S';
    else
        return 'P';
}

typedef struct {
    caveman_brain brain;
    int sharpness;
    int score;
} caveman;
void init_caveman(caveman* c, const caveman* m, double e) {
    int p, i, j;
    c->score = 0;
    for (p = 0; p < 3; ++p) {
        for (i = 0; i < PROGRAM_DIM; ++i) {
            for (j = 0; j < PROGRAM_DIM; ++j) {
                c->brain[p][i][j] = m->brain[p][i][j] + firandom() * e;
            }
        }
    }
}
int duel(caveman* c1, caveman* c2) {
    int winner;
    int turn;
    c1->sharpness = c2->sharpness = 0;
    for (turn = 0; turn < MAX_TURN_COUNT; ++turn) {
        winner = act(&c1->sharpness,
                     choose_action(c1->brain, c1->sharpness, c2->sharpness),
                     &c2->sharpness,
                     choose_action(c2->brain, c2->sharpness, c1->sharpness));
        if (winner)
            break;
    }
    if (winner < 0)
        ++c1->score;
    else if (winner > 0)
        ++c2->score;
    return winner;
}

/* portable tick-count for random seed */
#ifdef _WIN32
#include <Windows.h>
unsigned int tick_count() { return GetTickCount(); }
#else
#include <sys/time.h>
unsigned int tick_count() {
    struct timeval t;
    gettimeofday(&t, NULL);
    return 1000 * t.tv_sec + t.tv_usec / 1000;
}
#endif

int main(int argc, const char* argv[]) {
    const char* filename = DEFAULT_FILENAME;
    FILE* f;
    caveman* cavemen;
    caveman winner;
    int gen;
    double err = 1.0;
    int i;

    srand(tick_count()); rand();
    memset(&winner, 0, sizeof(caveman));

    if ((cavemen = (caveman*)malloc(sizeof(caveman) * CAVEMAN_COUNT)) == NULL) {
        printf("not enough memory!\n");
        return 1;
    }

    for (gen = 0; gen < GENERATION_COUNT; ++gen) {
        int i, j, k;
        const caveman* leader;

        printf("[Gen. %d / %d] ", gen + 1, GENERATION_COUNT);
        fflush(stdout);

        for (i = 0; i < CAVEMAN_COUNT; ++i)
            init_caveman(&cavemen[i], &winner, err);

        for (i = 0; i < CAVEMAN_COUNT; ++i) {
            for (j = i + 1; j < CAVEMAN_COUNT; ++j) {
                for (k = 0; k < DUEL_COUNT; ++k)
                    duel(&cavemen[i], &cavemen[j]);
            }
        }

        leader = cavemen;
        for (i = 1; i < CAVEMAN_COUNT; ++i) {
            if (cavemen[i].score > leader->score)
                leader = &cavemen[i];
        }

        printf("Caveman #%d wins with %d victories in %d duels\n",
               leader - cavemen + 1,
               leader->score, (CAVEMAN_COUNT - 1) * DUEL_COUNT);

        memcpy(&winner, leader, sizeof(caveman));
        err *= ERROR_BACKOFF;
    }

    free(cavemen);

    if (argc > 1)
        filename = argv[1];
    printf("Dumping brain to `%s'\n", filename);
    f = fopen(filename, "w");
    if (f == NULL) {
        printf("failed to open `%s'\n", filename);
        return 1;
    }
    for (i = 0; i < 3; ++i)
        write_program(f, winner.brain[i]);
    fclose(f);

    return 0;
}

සමඟ සම්පාදනය කරන්න : gcc genprog.c -ogenprog -w -O3. සමඟ ධාවනය කරන්න : ./genprog [output-filename].


වොට්සන්

ජයග්‍රාහී ගුහා මිනිසෙකුගේ ඩීඑන්ඒ කුමක්ද? සමහර විට මෙම වරදට පිළිතුර ඇත:

# That's the actual logic. Initialization goes below.
def run():
    if his_sharpness[-10] - turn / 15 + 1 + turn % 3 - his_sharpness[-6] < 0:
        act(B=0, S=0, P=100) # 7.21% chance
    elif his_sharpness[-6] + 1 - his_sharpness[-2] < 0:
        act(B=0, S=0, P=100) # 4.15% chance
    elif his_history[-3] - my_history[-1] <= 0 and my_sharpness[-1] - turn / 10 <= 0:
        act(B=0, S=100, P=0) # 11.34% chance
    elif his_sharpness[-1] == 0:
        act(B=0, S=100, P=0) # 27.84% chance
    else:
        act(B=100, S=0, P=0) # 49.46% chance

# Boring stuff go here...

import sys, random

# Actions
block, sharpen, poke, idle = range(4)

# Converts textual history to internal format
def convert_history(textual_history):
    return ["BSP".index(action) for action in textual_history]

# Calculates sharpness after performing an action sequence
def calculate_sharpness(history):
    return history.count(sharpen) - history.count(poke)

# Returns a list containing the sharpness at the end of each turn
def sharpness_history(history):
    return [calculate_sharpness(history[:i + 1]) for i in range(len(history))]

# Acts based on the probability distribution (B%, S%, P%)
def act(B, S, P):
    r = random.random() * 100
    print "BSP"[(r >= B) + (r >= B + S)]

# Setup data
textual_history = sys.argv[1] if len(sys.argv) > 1 else ","
my_history, his_history = (convert_history(h) for h in textual_history.split(','))
my_sharpness, his_sharpness = (sharpness_history(h) for h in (my_history, his_history))
turn = len(my_history)
my_history, his_history = ([idle] * 16 + h for h in (my_history, his_history))
my_sharpness, his_sharpness = ([0] * 16 + s for s in (my_sharpness, his_sharpness))

# Make a move
run()

සමඟ ධාවනය කරන්න: python Watson.py

වොට්සන් යනු ජානමය ඇල්ගොරිතමයක නිෂ්පාදිතයකි. ඩාවින් මෙන් නොව, මෙවර ජානමය දත්ත යනු සත්‍ය ඩොමේන් විශේෂිත භාෂාවකින් ලියා ඇති සත්‍ය වැඩසටහනකි (මෙහි පයිතන්ට පරිවර්තනය කර ඇත).


සරල අනුක්‍රමය විශාල ක්‍රීඩකයන්ට පහර දෙයි

මෙම කුඩා මිතුරා පුදුම සහගත ලෙස (හෝ, සමහර විට, එතරම් පුදුමයට කරුණක් නොවේ), විශේෂයෙන් නායකයින්ට එරෙහිව හොඳින් ක්‍රියා කරයි:

import sys
print "Simple Sequence Beats Big Players".split(' ')[
    len(sys.argv[1]) / 2 % 5 if len(sys.argv) > 1 else 0
]

සමඟ ධාවනය කරන්න: python SSBBP.py


මෙය සම්පාදනය කර ක්‍රියාත්මක කරන්නේ කෙසේද? එසේම, ප්‍රශ්නයේ සඳහන් පරිදි, ඔබට players/Darwinනාමාවලියෙහි ඇති ලිපිගොනු කියවීමට / ලිවීමට පමණක් හැකිය .
දොරක්නොබ්

O ඩෝර්ක්නොබ්: ස්ථාවරයි.
ඩාවින් බොට්

මෙම කේතය සම්පාදනය කිරීමේදී මම මෙම සම්පාදක දෝෂ ලබා ගනිමි . (මම ඉන්නේ උබුන්ටු 14.04 හි ය.)
දොරක්නොබ්

O ඩෝර්ක්නොබ්: ස්ථාවර. දැන් වැඩ කළ යුතුයි.
ඩාවින් බොට්

මට දැන් ලැබෙනවා undefined reference to `fmax'. - සංස්කරණය කරන්න - කමක් නෑ, මට ඇත්තෙන්ම අවශ්‍ය විය -lm.
දොරක්නොබ්

50

අනපේක්ෂිත ගුහා මිනිසා

me, he = (ARGV[0] || ' , ').split(',')

@possible_actions = %w[Sharpen Poke Block]

class String

  def sharpness
    @sharpness ||= count('S') - count('P')
  end

  def has_pointy_stick
    (1..4).cover? sharpness
  end

  def has_sword
    sharpness >= 5
  end

  def scary
    sharpness > 0
  end

end

def no action
  @possible_actions.delete(action)
end

def do!
  puts @possible_actions.sample[0]
end

no 'Block' if not he.has_pointy_stick

no 'Poke' if not me.scary

no 'Sharpen' if me.has_sword

no 'Block' if me.has_sword

do!

මෙම ගුහා මිනිසා සෑම වටයක්ම අහඹු ලෙස තෝරා ගනී, නමුත් සමහර ක්‍රියාවන් සමහර විට තේරුමක් නැති බව මම ඔහුට ඉතා සරළව පැහැදිලි කළෙමි. ඔබට විවිධ තර්කනයන් ප්‍රකාශ කිරීමට අවශ්‍ය නම් මෙම කේතය පිටපත් කිරීමට නිදහස් වන්න.

මෙය රූබි ය, 'unpredictable.rb' ලෙස සුරකින්න ruby unpredictable.rb


ඇත්තටම, no 'Block'මගේ විරුද්ධවාදියාට කඩුවක් තිබේ නම් එයද විය යුතුය.
njzk2

පළමු 'බ්ලොක්' ඇත්ත වශයෙන්ම එය ආවරණය කරයි: පොයින්ටි පොල්ලක් කඩුවක් නොවේ.
හිස්ටොක්‍රැට්

2
සහ ප්‍රකාශ unlessසඳහා ඔබ භාවිතා නොකරන්නේ ඇයි ? ( )no 'Block'no 'Pokeno 'Block' unless he.has_pointy_stick
wchargin

25

ගුහා වෛද්‍ය - ලුවා

"නව විදේශිකයින්ට මා අහිමි වේ, ඔවුන්ව හැදෑරීමට ඔවුන්ව තල්ලු කළේය"

ඔබ ගුහා වෛද්‍යවරයා තරම් රෝගීන් දැක ඇති විට, ඔබ ගුහා මිනිසාගේ මනස සැබවින්ම තේරුම් ගැනීමට පටන් ගනී (නැතහොත් මම බලාපොරොත්තු වෙමි). ගුහා වෛද්‍යවරයාගේ ක්‍රීඩාව පිරිසිදු උපක්‍රමයක් වන අතර, ඔහු තම ප්‍රතිවාදියා නිරායුධ කිරීමේ උත්සාහයක් ලෙස අවහිර කරන සිදුරු එනතෙක් බලා සිටියි, නමුත් කඩුව සෑදීමට ඔහු විරුද්ධ වීමට ඉඩ නොදෙයි. මුවහත් කිරීම ආරක්ෂිත වන්නේ කවදාදැයි අනාවැකි කීමට ඔහු උත්සාහ කරයි.

caveman={havePointyStick=function (t)     
   local pointy=0   
   for i in t.stick:gmatch("[SP]") do
    if i=="S" then 
      pointy=pointy+1
    elseif pointy>0 then
      pointy=pointy-1
    end   
   end 
 t.sharp=pointy>0
 t.lastmove=t.stick:sub(t.stick:len())
 return pointy 
 end,
    Stupid=function (stick)--I put way to much effort in this...
      o = {} 
      setmetatable(o, caveman)
      o.smartness=0
      o.stick=stick
      caveman.__index = caveman
      return o
    end,
     Smart= function (stick)
      o ={} 
      setmetatable(o, caveman)
      o.smartness=100
      o.stick=stick
      caveman.__index = caveman
      return o
    end
       }


    if arg[1]==nil then  
       print("S")
    else   
      split=arg[1]:find(",")  
      me=caveman.Smart(arg[1]:sub(0,split-1)) 
      he=caveman.Stupid(arg[1]:sub(split+1)) 
      mesharp=me:havePointyStick()  
      hesharp=he:havePointyStick()
      if not he.sharp and mesharp<5 then print("S")--Go for the sword  
      elseif mesharp>4 or me.stick:len()>93 then
         if (mesharp>0) then print("P")--We're losing/about to win or time's running out
         else print("S")--uh-oh
         end
      else 
         u,g,h=he.stick:match("(B+)S+(B+)S+(B+)$")
         g,u,h=he.stick:match("(P+)S+(P+)S+(P+)$")
         if u~=nil and u==g and g==h then 
            if not me.sharp then print("S")
            else print("P")
            end
         elseif me.stick:match("SBSB$")~=nil then print("B")
         elseif he.stick:len()>7 and he.stick:match("P")==nil and me.lastmove~="S" then print("S")
         else
         b,u,h=he.stick:match("(B*)(S+)(B*)$")
         if u~=nil then
             if (h:len()>3 and me.lastmove=="B") or (b:len()>h:len() and b:len()>0 and h:len()>0) then print("S")
             else print("B")
             end
          else print("B")
          end   
      end   
   end 
end

සමඟ ධාවනය කරන්න: lua CaveDoctor.lua


3
මෙය වත්මන් ප්‍රමුඛ පුවරුවේ දෙවරක් පමණක් අහිමි වේද? oO
justhalf

සංශෝධනය 5 දෝෂ රාශියක් විසි කරයි, එබැවින් සංශෝධන 4 යනු වර්තමාන අත්හදා බැලීම් වටයට ඇතුළත් කර ඇත.
දොරක්නොබ්

O ඩෝර්ක්නොබ් මම හිතන්නේ මම ඒවා සියල්ලම සවි කළෙමි, කෙසේ වෙතත් සත්‍ය තර්කනයට ඇත්තේ එක් වෙනසක් පමණි.
නෙක්සස්

21

විදේශීය කේව්මන්

ForeignCaveman ඔබ දැන් කී දේ ගැන කිසිම අදහසක් නැත. ඔහු ... දේවල් කරනවා.

javac ForeignCaveman.java එවිට java ForeignCaveman

public class ForeignCaveman {

    public static void main(String[] args) {
        int m = (int) (Math.random()*3);
        switch(m) {
            case 0: System.out.println('B'); 
                    break;
            case 1: System.out.println('P'); 
                    break;
            case 2: System.out.println('S'); 
                    break;
        }
   }
}

12
මෙය කොතරම් නරකද යන්නට බොහෝ දුරට ඉඩ තිබේ
කෙවින් එල්

20

උප නායක

දොරක්නොබ් leader නායකයාය. මට නායකයා වීමට අවශ්‍යයි! නායකයා වීමට සුපිරි බුද්ධිමත් වැඩසටහනක් අනුගමනය කරන්න!

සම්පාදනය: javac ViceLeader.javaධාවනය: java ViceLeader.

public class ViceLeader {

    public static void main(String[] args) {
        if (args.length == 0 || !args[0].contains(",")) {
            System.out.print("S");
            return;
        }
        String[] history = args[0].split(",");
        int mySharpness = getSharpness(history[0]);
        int enemySharpness = getSharpness(history[1]);

        // enough sharpness to strike until end of game
        if (100 - history[0].length() <= mySharpness) {
            System.out.print("P");
            return;
        }

        // sharpen while secure
        if (enemySharpness == 0) {
            System.out.print("S");
            return;
        }

        // enemy blocks the whole time and I didn't use this tactic on last turn
        if (isBlocker(history[1]) && history[0].charAt(history[0].length() - 1) != 'S') {
            System.out.print("S");
            return;
        }

        // TAKE HIM OUT!
        if (enemySharpness == 4 || mySharpness >= 5) {            
            System.out.print("P");
            return;
        }

        // enemy sharpens the whole time => sharpen to strike on next turn
        if (isSharpener(history[1])) {
            System.out.print("S");
            return;
        }

        System.out.print("B");
    }

    private static int getSharpness(String history) {
        int sharpness = 0;
        for (char move : history.toCharArray()) {
            if (move == 'S') {
                sharpness++;
            } else if ((move == 'P' && sharpness > 0) || move == '^') {
                sharpness--;
            }
        }
        return sharpness;
    }

    private static boolean isBlocker(String history) {
        if (history.length() < 3) {
            return false;
        }
        for (int i = history.length() - 1; i > history.length() - 3; i--) {
            if (history.charAt(i) != 'B') {
                return false;
            }
        }
        return true;
    }

    private static boolean isSharpener(String history) {
        if (history.length() < 3) {
            return false;
        }
        for (int i = history.length() - 1; i > history.length() - 3; i--) {
            if (history.charAt(i) != 'S') {
                return false;
            }
        }
        return true;
    }
}

මෙය if (enemySharpness <= 4 || mySharpness >= 5)එදිරිව නොවන්නේ ඇයි ==?
durron597

@ durron597 මක්නිසාද යත් මට අවශ්‍ය වන්නේ සතුරාට ඊළඟ වාරයේදී කඩුවක් සෑදිය හැකි නම් පමණි (ඔහු බොහෝ විට එය කරනු ඇත). VizeLeader බොහෝ විට සිදුරු නොකරයි, එය නියම වේලාවට කරයි.
CommonGuy

නමුත් ඔබට කඩුවක් ඇති අතර ඔබේ ප්‍රතිවාදියාට එය නැත ...
durron597

ur durron597 නැත, එය OR ප්‍රකාශයකි. එහි තේරුම "ප්‍රතිවාදියාට කඩුවක් ඇත්නම් හෝ ඔහුට කඩුවක් තිබේ නම් ඔහුට පහර දෙන්න" යන්නයි.
CommonGuy

8
ඔහ් යහපත්කම. තවත් කෝපි කෝප්පයක් ලබා ගැනීමට කාලය :) හෝ නව අක්ෂි කාච
durron597

15

සමහර විට මාකෝව් 2.1

අනෙක් ගුහා මිනිසා කුමක් කරනු ඇත්දැයි අනාවැකි කීමට එය මාකෝව් දම්වැල් භාවිතා කරන බව මම සිතමි, නමුත් මාකෝව් දම්වැල් පිළිබඳ විකිපීඩියා පිටුව දෙස කෙටියෙන් බැලූ අතර එය ඕනෑවට වඩා පෙළ ඇති බව තීරණය කළෙමි.

එය වට 30 ක් පණපිටින් සිටීමට උත්සාහ කරන අතර පසුව වත්මන්-ඊළඟ රාජ්ය වෙනස්කම් සමඟ වගුවක් සාදයි, අනෙක් ගුහා මිනිසා විසින් කරනු ඇතැයි සිතන දෙයට ප්රතික්රියා කරයි.

කේතයේ අනවශ්‍ය ප්‍රකාශ රාශියක් අඩංගු වන නමුත් එය ඉතා හොඳින් ක්‍රියාත්මක වේ.

සංස්කරණය කරන්න

තර්කනයේ අඩුපාඩුවක් අනාවරණය විය. දැන් එය සැබවින්ම යමක් කරන්නේ එය කඩුවක් ඇති විටය.

$ python3 players/MaybeMarkov/MaybeMarkov.py

import sys, itertools
from operator import itemgetter
from collections import defaultdict

SHARPEN, POKE, BLOCK, HALP = 'SPB?'

all_actions = SHARPEN, POKE, BLOCK
always = 1

def do(action):
    print(action)
    exit(0)

if len(sys.argv) < 2:
    do(SHARPEN)

class status:
    def __init__(self, actions):
        self.step = len(actions)
        self.last = actions[-1]
        self.sh = self.sharpness = actions.count(SHARPEN) - actions.count(POKE)
        self.dull = self.sharpness <= 0
        self.has_sword = self.sharpness >= 5
        self.actions = actions
        self.ratio = {act:actions.count(act)/self.step for act in all_actions}
        self.can_do = set(all_actions)

        if self.dull:
            self.can_do.remove(POKE)

    def can(self, action):
        return action in self.can_do


me, he = map(status, sys.argv[-1].split(','))
turns = me.step

if he.has_sword:
    if me.can(POKE)                :do(POKE)
    if always                      :do(SHARPEN)

if me.has_sword:
    if he.last != POKE and me.last == BLOCK :do(POKE)
    if he.can(POKE)                :do(BLOCK)
    if always                      :do(POKE)

if not he.can(POKE)                :do(SHARPEN)

if turns <= 4                      :do(BLOCK)
if turns < 30:
    if he.ratio[SHARPEN] == 1:
        if me.can(POKE)            :do(POKE)
        if always                  :do(SHARPEN)
    if always                      :do(BLOCK)

if turns > 97:
    do(POKE)

def react_on(action):
    do({
        HALP    : BLOCK,
        SHARPEN : POKE,
        POKE    : BLOCK,
        BLOCK   : SHARPEN
    }[action])

states = tuple(itertools.product(all_actions, all_actions))
change = defaultdict(lambda:defaultdict(lambda:0))
count  = defaultdict(lambda:0)

for i in range(1, turns):
    prev = me.actions[i-1], he.actions[i-1]
    now  = me.actions[i]  , he.actions[i]
    change[prev][now] += 1
    count[prev] += 1

current = change[me.last, he.last]
prediction = HALP

if len(current) is 0:
    do(BLOCK)

if len(current) is 1:
    if tuple(current.values())[0] > turns / 7:
        prediction = tuple(current.keys())[0][1]

counts = itemgetter(1)

if len(current) > 1:
    key1, value1 = max(current.items(), key=counts)
    current[key1] *= 0.9
    key2, value2 = max(current.items(), key=counts)
    if key1 == key2:
        prediction = key1[1]

react_on(prediction)

14

ආවර්තිතා සිකාඩා කැව්මන්

මෙම තරමක් දක්ෂ ගුහා මිනිසා යම් දෙයක් අධ්‍යයනය කර ඇත දෝෂයක් සිකාඩා නම් අංකයෙන් ප්‍රයෝජන ගැනීමට කිසිවෙකුට ඔවුන්ගේ ජීවන රටාව වෙනස් කළ නොහැකි බව අවබෝධ .

එය ජීවිතයේ වැඩි කාලයක් සැඟවී / අවහිර කරයි, නමුත් ඉඳහිට සිදුරු කරයි. එය කඩු වලට ගොදුරු විය හැකි බවටත්, සම්පූර්ණ චක්‍රයක් නිරුපද්‍රිතව සැරයටියකින් වැය කරන බවටත්, එය සම්පූර්ණයෙන්ම නොපැහැදිලි වූ විට ඔබේ සැරයටිය මුවහත් කර ගැනීමටත් වග බලා ගන්න. අනෙක් අය එයින් බලාපොරොත්තු වන්නේ එයයි ... මේ සිකාඩා නොවේ

සම්පාදනය කිරීමට: මොනෝ ක්‍රමලේඛය ක්‍රියාත්මක කිරීමට mcs program.cs

public class PeriodicalCicadaCaveman
{
  const int Periodic = 13; //Could be 17
  public static void Main(string[] args)
  {
    if (args.Length == 0) 
    {
          System.Console.WriteLine("S");
          return;
    }
    var arg1 = args[0];
    if(arg1.Length == 0) 
    {
        //Always start with a sharp stick
        System.Console.WriteLine("S");
        return;
    }
    var myHistory = arg1.Split(',')[0];
    var theirHistory = arg1.Split(',')[1];
    int sharpness = 0;
    int timeElapsed =  myHistory.Length;

    for(int i = 0; i < timeElapsed; i++)
    {
        if(myHistory[i] == 'S')  
        {
            sharpness++;
        }
        if(myHistory[i] == 'P')
        {
            sharpness--;
        }
    }

    if((myHistory.Length % 13) == 0 
            || timeElapsed > 90 // Running out of time! To hell with the routine
        )
    {
        //The Secada strikes!
        if(sharpness > 1)
        {
            System.Console.WriteLine("P");
            return;
        }
        else
        {
            System.Console.WriteLine("S"); 
            return;
        }
    }
    System.Console.WriteLine("B"); 

  }

}

සංස්කරණය කරන්න: තියුණු බව වෙනස් කළා - කේතය ... මම විදිනවා නම් මම දිනනවා හෝ මගේ සැරයටිය අඳුරු වේ

Edit2: බොබ්ස් යෝජනාවට එක් කරන ලදි

සංස්කරණය කරන්න: තියුණු 2 වන විට පමණක් විදින ලෙස වෙනස් කර ඇත, සැරයටිය කවදා හෝ ශුන්‍ය නම් අනෙක් පුද්ගලයා කඩුවක් සෑදිය හැකිය.


1
මම උබුන්ටු මත දුවනවා; මොනෝ යටතේ මෙය සම්පාදනය වේද? එසේ නම්, මම එය සම්පාදනය කරන්නේ කෙසේද සහ එය ක්‍රියාත්මක කරන්නේ කෙසේද?
දොරක්නොබ්

ඇත්තම කිව්වොත් මම දන්නේ නැහැ. මම ඇඳට යන්න සූදානම්. මට එය හෙට උදේ වැඩට යන විට ජාවා වෙත නැවත ලිවිය හැකිය. ජාවා කේතය බොහෝ දුරට සමාන විය යුතුය.
මිකී මවුස්

5
O ඩෝර්ක්නොබ් mcs program.csවිසින් එය සම්පාදනය කරනු ඇත, mono programඑය ක්‍රියාත්මක කරනු ඇත, නමුත් ඔබට ඒවා ආදේශ කිරීමට අවශ්‍ය වනු foo.Dump();ඇත System.Console.WriteLine(foo);(හෝ දිගු කිරීමේ ක්‍රමයක් එක් කරන්න public static void Dump(this string value) { System.Console.WriteLine(value); }).
බොබ්

@ බොබ් ස්තූතියි යාළුවා, මම ඔබේ ව්‍යාප්ති ක්‍රමයට එකතු කර ඇත්තෙමි.
මිකී මවුස්

සමාවන්න, සැබෑ පෙරනිමි ගොනු mcsඇත ජනනය <filename>.exe, උදා: program.csවනු ඇත program.exe. එබැවින් run විධානය වනු ඇත mono program.exe. (මා කලින් අදහස් දක්වන අවස්ථාවේ මට මොනෝ වෙත ප්‍රවේශය නොතිබුණි.)
බොබ්

14

FancyTechnoAlgorithm

විසිතුරු තාක්ෂණික පරිගණක වැඩසටහන සඳහා විසිතුරු තාක්ෂණික ඇල්ගොරිතමයක්.

ගුහා මිනිසා සටන දිගටම කරගෙන යයි. කේව්මන් තරහයි. එබැවින් ගුහා මිනිසා පරිගණක පාසලට ගොස් ඇල්ගොරිතම සාදන්න.

import random, sys  # Need import some advanced techno code

if __name__ == '__main__':  # If fancy techno computer program is main

    try:  # Me try use fancy techno algorithm!

        me, he     = sys.argv[1].split(",")
        mePointy   = me.count("S") - me.count("P")
        hePointy   = he.count("S") - he.count("P")
        meCanPoke  = mePointy > 0
        heCanPoke  = hePointy > 0
        meHasSword = mePointy >= 5
        heHasSword = hePointy >= 5
        meScary    = meCanPoke + meHasSword 
        heScary    = heCanPoke + heHasSword

        # Me donno fancy coding math algoritm.
        # Math confuse. Me code work, me happy.
        if he[-6:] == "SB"*3:
            print "SP"[meCanPoke]
        elif (len(he) > 30 and he[-3:].count("B") > 2) or \
             (hePointy > 2 and he.count("SSBB") > 0 and he.count("BBS") > 0):
            if meHasSword:
                print "P"
            else:
                print "SB"[me[-1] == "S"]
        elif hePointy > 3 and he.count("BBS") > 2:
            print "SP"[me[-1] == "S"]
        else:
            print random.choice(\
                [["S", "SP", "P" ],\
                 ["B", "B" , "P" ],\
                 ["S", "P" , "P" ]][heScary][meScary])

    except:  # Fancy techno algorithm Failed... Me just sharpen.
        print "S"

පයිතන් 2 වැඩසටහන. ධාවනය කිරීමට:python fancytechnoalgorithm.py


ආදාන නොමැති විට මෙය කැඩී යයි (එනම් පළමු වාරයේ). ඔබට එය හැසිරවිය යුත්තේ කෙසේදැයි මම නොදනිමි, එබැවින් මට එය පළමු වටයේ පරීක්ෂණ වලින් බැහැර කිරීමට සිදුවේ.
දොරක්නොබ්

ආදාන පළමු ආදානය සඳහා එය "," හෝ "" ද? මම හිතන්නේ එය දෙවැන්නයි.
දෛශිකකරණය කරන ලද

පළමු ආදානය සඳහා, තර්ක නොමැත (එය ක්‍රියාත්මක වන්නේ python StickSharpener.py).
දොරක්නොබ්

O ඩෝර්ක්නොබ් මම එය සංස්කරණය කර ඇත්තෙමි. එය දැන් ක්‍රියාත්මක වේදැයි බලන්න.
දෛශිකකරණය කරන ලද

හරි, ස්තූතියි! මම මෙය ඊළඟ වටයේ අත්හදා බැලීම්වලට ඇතුළත් කරමි.
දොරක්නොබ්

14

මුරකරු

ඔහු තම ප්‍රතිවාදියාගේ චලනයන් දෙස බලා සිටින අතර, ඔහු පහර දීමට පෙර සෑම විටම ඔවුන්ගේ අත පෙන්වීමට ඔවුන්ට ඉඩ දෙයි. කඩුවකට වැඩ කිරීම අතපසු කරන අය සඳහා ඔහු විශේෂයෙන් සූදානම් ය.

import sys, random

if len(sys.argv) > 1:
    history_self, history_other = sys.argv[1].split(',')
else:
    history_self = history_other = ""

def sharpness(history):
    ret = 0
    for action in history:
        if action == 'S':
            ret += 1
        elif action == 'P' and ret > 0:
            ret -= 1
    return ret

def weighted_random(dict):
    i = random.randrange(sum(dict.values()))
    for k, v in dict.items():
        i -= v
        if i < 0:
            return k

def action(history_self, history_other):
    sharpness_self = sharpness(history_self)
    sharpness_other = sharpness(history_other)
    if sharpness_self >= 5:
        return 'P'
    elif sharpness_other == 0:
        return 'S'  #Guaranteed safe
    elif sharpness_other == 1:
        #If the opponent isn't interested in a sword, time is on our side
        block_count = len(history_self) - len(history_self.rstrip('B'))
        if block_count > 3 and random.randrange(block_count) > 3:
            return 'S'
        else:
            return 'B'
    elif sharpness_other >= 5:
        return 'S'
    else:
        #Search for a weakness
        for i in range(10, 2, -1):
            if history_other[-i:] == history_other[-i*2:-i]:
                predicted_action = history_other[-i]
                if predicted_action == 'S':
                    if sharpness_self > 0:
                        return 'P'
                    else:
                        return 'S'
                elif predicted_action == 'B':
                    return 'S'
                elif predicted_action == 'P':
                    return 'B'
        #Presumably the opponent is random - respond with some educated randomness
        if sharpness_self == 0:
            return random.choice(['S','S','B'])
        return weighted_random({
            'S': sharpness_self,
            'B': 1,
            'P': sharpness_other,
        })

if __name__ == "__main__":
    print(action(history_self, history_other))

ගොනුවේ නම: watcher.py

ධාවනය කිරීමට: python watcher.py

බැසිලිස්ක්

ඔහු දෙස සමීපව බලන අය විනාශ කිරීමට උත්සාහ කරයි. මුරකරුට නිරන්තරයෙන් පහර දෙයි, නමුත් සමස්තයක් වශයෙන් නරක අතට හැරෙනු ඇත.

import sys, random

if len(sys.argv) > 1:
    history_self, history_other = sys.argv[1].split(',')
else:
    history_self = history_other = ""

def sharpness(history):
    ret = 0
    for action in history:
        if action == 'S':
            ret += 1
        elif action == 'P' and ret > 0:
            ret -= 1
    return ret

def action(history_self, history_other):
    sharpness_self = sharpness(history_self)
    sharpness_other = sharpness(history_other)
    if sharpness_self >= 5:
        return 'P'
    elif len(history_self) < 13:
        return 'SBBSBPSBBSBPP'[len(history_self)]
    elif 5 + 5 * sharpness_self < random.randrange(len(history_self)):
        return 'S'
    elif sharpness_other == 0:
        if sharpness_self == 0 or random.randrange(sharpness_self) == 0:
            return 'S'
        else:
            return 'P'
    elif sharpness_other == sharpness_self:
        return 'P'
    else:
        return 'B'

if __name__ == "__main__":
    print(action(history_self, history_other))

ගොනුවේ නම: basilisk.py

ධාවනය කිරීමට: python basilisk.py

නැෂ්

එක් එක් පියවර එහි අවදානම් සහ විපාක සඳහා හේතු වන සම්භාවිතාවක් සහිතව තෝරා ගැනීමෙන් ඔහුගේ ප්‍රතිවාදියාගේ තේරීම් අනවශ්‍ය බවට පත් කිරීමට උත්සාහ කරයි

import sys, random

if len(sys.argv) > 1:
    history_self, history_other = sys.argv[1].split(',')
else:
    history_self = history_other = ""

movemap = [ [(1.000000,0.000000),(0.473863,0.526137),(0.394636,0.605364),(0.490512,0.509488),(1.000000,0.000000)],
        [(0.695328,0.000000,0.304672),(0.275953,0.582347,0.141700),(0.192635,0.700391,0.106974),(0.196343,0.689662,0.113995),(0.289968,0.544619,0.165413)],
        [(0.570635,0.000000,0.429365),(0.236734,0.570126,0.193139),(0.167197,0.687133,0.145670),(0.173139,0.667169,0.159693),(0.264911,0.475316,0.259773)],
        [(0.490512,0.000000,0.509488),(0.196309,0.578888,0.224803),(0.135744,0.692358,0.171898),(0.140638,0.663397,0.195965),(0.220709,0.426989,0.352302)],
        [(1.000000,0.000000,0.000000),(0.147944,0.636760,0.215296),(0.089478,0.737358,0.173165),(0.087259,0.704604,0.208137),(0.128691,0.435655,0.435655)]  ]

def sharpness(history):
    ret = 0
    for action in history:
        if action == 'S':
            ret += 1
        elif action == 'P' and ret > 0:
            ret -= 1
    return ret

def action(history_self, history_other):
    sharpness_self = sharpness(history_self)
    sharpness_other = sharpness(history_other)
    if sharpness_self >= 5:
        return 'P'
    elif sharpness_other >= 5:
        return 'S'
    moves = movemap[sharpness_self][sharpness_other]
    v = random.random()
    if v < moves[0]:
        return 'S'
    elif v < moves[0] + moves[1]:
        return 'B'
    else:
        return 'P'

if __name__ == "__main__":
    print(action(history_self, history_other))

මෙය තරමක් නැෂ් සමතුලිතතාවය නොවේ (මගේ උපාය උත්පාදක යන්ත්‍රයට යම් අස්ථාවරත්වයක් ඇත), නමුත් එය ආසන්නයි.

කුතුහලය නිසා, එක් එක් ක්‍රීඩා තත්වයන් තුළ මෙම බොට් ජයග්‍රහණය කිරීමට ඇති ඉඩකඩ පිළිබඳ ඇස්තමේන්තු මෙන්න:

map = [ [0.50000000,0.26337111,0.15970733,0.08144046,0.00000000,0.00000000],
        [0.73662889,0.50000000,0.37879183,0.28035985,0.16622410,0.00000000],
        [0.84029267,0.62120817,0.50000000,0.39441630,0.26038353,0.00000000],
        [0.91855954,0.71964015,0.60558370,0.50000000,0.35246401,0.00000000],
        [1.00000000,0.83377590,0.73961647,0.64753599,0.50000000,0.00000000],
        [1.00000000,1.00000000,1.00000000,1.00000000,1.00000000,0.50000000] ]

ගොනුවේ නම: nash.py

ධාවනය කිරීමට: python nash.py

ෆින්ට්

ඔහුගේ ප්‍රතිවාදියාගේ ආරක්ෂාව පරීක්ෂා කිරීම සඳහා ඉක්මන් ප්‍රහාරයකින් විවෘත වේ.

import sys, random

if len(sys.argv) > 1:
    history_self, history_other = sys.argv[1].split(',')
else:
    history_self = history_other = ""

def sharpness(history):
    ret = 0
    for action in history:
        if action == 'S':
            ret += 1
        elif action == 'P' and ret > 0:
            ret -= 1
    return ret

def action(history_self, history_other):
    sharpness_self = sharpness(history_self)
    sharpness_other = sharpness(history_other)
    if sharpness_self >= 5:
        return 'P'
    elif len(history_self) < 2:
        return 'SP'[len(history_self)]
    elif history_other[1] == 'P':
        # Fierce fight
        if sharpness_self == 0:
            return 'S'
        elif history_self[-(1 + history_self.count('P'))] == 'S':
            return 'P'
        else:
            return 'B'
    else:
        # Smart guy
        if sharpness_other == 1:
            return 'B'
        elif history_self[-1] != 'S' or history_self[-4:] == 'BSBS':
            return 'S'
        elif history_other.count('S') > history_other.count('B'):
            return 'P'
        else:
            return 'B'

if __name__ == "__main__":
    print(action(history_self, history_other))

ගොනුවේ නම: feint.py

ධාවනය කිරීමට: python feint.py

LatePokeBot

PokeBot ගේ කුඩා සහෝදරයා. කිසි විටෙකත් දුර්වලකම නොපෙන්වයි, නමුත් ඔහුගේ ලොකු සහෝදරයා මෙන් සටන් කිරීමට උත්සාහ කරයි.

import sys, random

if len(sys.argv) > 1:
    history_self, history_other = sys.argv[1].split(',')
else:
    history_self = history_other = ""

def sharpness(history):
    ret = 0
    for action in history:
        if action == 'S':
            ret += 1
        elif action == 'P' and ret > 0:
            ret -= 1
    return ret

def action(history_self, history_other):
    sharpness_self = sharpness(history_self)
    return 'SSP'[sharpness_self]

if __name__ == "__main__":
    print(action(history_self, history_other))

ගොනුවේ නම: latepokebot.py

ධාවනය කිරීමට: python latepokebot.py


ඔබට :බැසිලිස්ක් හි අතුරුදහන් විය; මම ඔබ වෙනුවෙන් එය සවි කළෙමි
දොරක්නොබ්

මෙම ඉදිරිපත් කිරීම යම් අවස්ථාවක දී යම් ආකාරයක දෝෂයක් හෝ ව්‍යතිරේකයක් විසි කළේය; ඊළඟ වටයේ අත්හදා බැලීම්වලට පෙර එය නිවැරදි කිරීම පිළිබඳව සොයා බැලීමට ඔබට අවශ්‍ය විය හැකිය. (බැසිලිස්ක් එක)
ඩෝර්ක්නොබ්

O ඩෝර්ක්නොබ් මම බැසිලිස්ක් සඳහා ආරම්භක අනුක්‍රමය තෝරා ගත්තේ ද මුරකරු සහ ගුහා වෛද්‍යවරයා විසින් කරන ලද උපකල්පන දෙස බැලීමෙන් සහ එම උපකල්පන වැරදි ලෙස වැරදි වන අනුක්‍රමයක් සොයා ගැනීමෙනි. එය "ගුහා මිනිසුන් සාධාරණ" නීතිය උල්ලං? නය කරයිද?
බ්‍රිලියන්ඩ්

යන්න නාෂ්! ඔබගේ P = 0 විකල්පයන් මග හැරීමට තරම් බුද්ධිමත් සියලු බොට් වලට එරෙහිව ඔබේ තරඟ වලින් අඩක් ජය ගන්න!
aschepler

12

PokeBot

රූබි වලින් ලියා ඇත.

puts((ARGV.shift || "P,").match(/(.),/)[1] == "P" ? "S" : "P")

සමඟ ධාවනය කරන්න ruby pokebot.rb.

මෙම බොට් ඉතා දක්ෂ නැත; එය සාමාන්‍ය ගුහා මිනිසා කෙසේ හෝ තනිවම කරනු ඇති දේ ගැන කරයි.


9

රෝගියා වුල්ෆ් v2.0

අඳුරු නම් තියුණු වේ, සතුරාට ඊළඟ වාරය කඩුවක් තිබේ නම් හෝ සතුරා අඳුරු නම්, වෙනත් ආකාරයකින් අවහිර කරයි.

my ($me,$him) = split(/,/,$ARGV[0]);
if(!defined $me) {
    print "S";
    exit;
}
my $mysharpness =()= ($me =~ /S/g);
$mysharpness -= ($me =~ /P/g);
my $opponentsharpness =()= ($him =~ /S/g);
$opponentsharpness -= ($him =~ /P/g);
if($mysharpness == 0) {
    print "S";
} elsif($opponentsharpness <= 0 || $opponentsharpness == 4) {
    print "P";
} else {
    print "B";
}

සමඟ ධාවනය කරන්න

perl patientwolf.pl

සංස්කරණය කරන්න: දෝෂයක් පෙන්වා දුන් @sylwester ට ස්තූතියි


කොමා මඟින් වෙන් කරන ලද ඉතිහාස දෙකම සමඟ ඔබට එක් තර්කයක් පමණක් ලැබෙන බැවින් ඔබ එය වැරදියට විග්‍රහ කරයි. උදා. PatientWolf.pl SB,SPඑය කරන්නේ Pඑය තියුණු දණ්ඩක් ඇත සිතන නිසා.
සිල්වෙස්ටර්

Yl සයිල්වෙස්ටර් එය නිවැරදි නොවේ. පළමු පේළියේ පළමු තර්කය $ මට සහ දෙවන තර්කය $ ඔහුට
පැවරේ

CavemanDuel වැඩසටහන තර්ක දෙකක් භාවිතා නොකරයි, එකක් පමණි. උදා. perl patientwolf.pl "SB,SP". ඔබ කළ යුත්තේ my($me,$him) = split/,/ $ARGV[0];සහ if( @ARGV ) {print "S";exit}.
සිල්වෙස්ටර්

Yl සිල්වෙස්ටර් හරි, ඔබ දකින්නේ කුමක්දැයි මට පෙනේ. එය OP වෙතින් හෝ මම බැලූ බැල්මට පාලක කේතයට විසි කළේ නැත. මම ඒක ඉක්මනින්ම හදන්නම්
මිනීමරු

9

ද්විමය ගුහා මිනිසා

තියුණු කරන්න, පඩිපෙළ, නැවත කරන්න

අවහිර කිරීම සිස්සි සඳහා වන අදහස මත පදනම්ව, මෙම ගුහා මිනිසා ඉතිරි විකල්ප දෙක අතර වෙනස් වේ.

public class BinaryCaveman { 

    public static void main(String[] args) {
        int timelapse = 0;
        if(args.length>0)
        {
            timelapse = ((args[0].length() - 1) / 2);
        }
        switch(timelapse % 2) 
        {
            case 0: System.out.println('S'); 
                    break;
            case 1: System.out.println('P'); 
                    break;
        }
    }
}

සමඟ සම්පාදනය කරන්න javac BinaryCaveman.java

සමඟ ධාවනය කරන්න java BinaryCaveman

සංස්කරණය කරන්න: නූල් අරා වල වික්‍රමාන්විතයන් ..... args.length () දෝෂයක් විසි කරයි. args.length සැමවිටම ප්‍රතිලාභ 1. args [0] .length () අරාවෙහි පළමු නූලෙහි දිග ලබා දෙයි.

සංස්කරණය 2: ඩෝර්ක්නොබ්, බ්‍රිලියන්ඩ් සහ සිල්වෙස්ටර්ගේ උදව්වට ස්තූතියි. ස්තූතියි යාලුවනේ.


@ මාටින්බට්නර් මට එක් ක්‍රීඩකයෙකු විසින් අතීත ඉදිරිපත් කිරීම් ගණන ලබා ගැනීම සඳහා 1 - 2 න් බෙදීමට අමතක විය. එය ස්ථාවරයි. ඩෝර්ක්නොබ්ගේ ඉදිරිපත් කිරීම මට තේරුම් ගත නොහැක, රුබී මට ප්‍රායෝගිකව විහිළුවක්. ඔහුගේ සෑම විටම ආරම්භ වන්නේ තියුණු කිරීමකින්ද?
Red_Shadow

ඔව්, ඔහුගේ අවසාන පියවර වූයේද Pනැතහොත් Sප්‍රතිවිරුද්ධ දේද යන්න ඔහු පරීක්ෂා කරයි. තවම ඉතිහාසයක් නොමැති නම්, ඔහු ඉතිහාසය මවා P,පෙන්වයි (එමඟින් ඔහු Sපළමුව එය කිරීමට පෙළඹේ).
මාටින් එන්ඩර්

එකම ප්‍රතිදානයේ ප්‍රති different ලයක් ලෙස වෙනස් ප්‍රවේශයන් දෙකක්. එය නීතිවලට පටහැනිද?
Red_Shadow

බොහෝ විට නැත, මම ඔබට දන්වන්නම්.
මාටින් එන්ඩර්

2
මම එය විය යුතුයි කියලා @Doorknob args[0].length()නොව args.length.
බ්‍රිලියන්ඩ්

8

CavekidBlocks

අ crying න සහ බියට පත් ගුහා ළමයෙක් පහසු ගොදුරක් මෙන් විය හැකිය. ඔහුගේ ලස්සන මුහුණ ඔබව රවටා ගැනීමට ඉඩ නොදෙන්න.

import sys, math, random
def count(a):
    s = 0
    for i in range(len(a)):
        if a[i] == 'P': s-=1
        elif a[i] == 'S': s+=1
        if s < 0: s = 0
    return s
kid = []
scary_adult = []
what2do = 'Sharpen the Stick! Why not? Adult may be doing the same. DONT trust adults!'
if len(sys.argv) > 1:
    kid, scary_adult = sys.argv[1].split(",")
    kid_stick_sharpness = count( kid )
    scary_adult_stick_sharpness = count( scary_adult )
    if (scary_adult_stick_sharpness >= 2):
        what2do = "Block! Block! Block! Adult's stick looks scary sharp."
    elif (kid_stick_sharpness > 0):
        what2do = 'Point your Stick to the adult. It may scary him.'
    else:
        what2do = 'Sharpen the Stick!'

    # Roll d20 for a courage check.
    dice = random.randint(1,20)
    if (dice > 15): what2do = 'Poke the adult! Critical Hit!'
    elif (dice <= 5): what2do = 'Block! Block! Block!'
print(what2do[0])

සමඟ ධාවනය කරන්න python3 cavekidblocks.py

චාජර්මන්

මෙම ගුහා මිනිසා ඉතා ගතානුගතික ය. ඔහුගේ ආයුධය ආරෝපණය කිරීමට උත්සාහ කරන අතර අවශ්‍ය විටදී පමණක් පහර දෙයි.

import sys, math, random
def countSharpness(a):
    s = 0
    for i in range(len(a)):
        if a[i] == 'P': s-=1
        elif a[i] == 'S': s+=1
        if s < 0: s = 0
    return s
def getHistory():
    me = ""
    him = ""
    if len(sys.argv) > 1:
        me, him = sys.argv[1].split(",")
    return me,him
if __name__ == '__main__':
    me, him = getHistory()
    me_s = countSharpness(me)
    him_s = countSharpness(him)
    answer = 'B'
    # First Case
    if (len(me) == 0):
        answer = 'S'
    # I have a sword
    elif (me_s == 5):
        answer = 'P'
    # Cant let he gets a sword
    elif (him_s == 4):
        answer = 'P'
    # His sword is dull
    elif (him_s == 0):
        # He may try to sharp
        # Cant attack? Sharp my stick
        if (me_s == 0): answer = 'S'
        else:
            if (random.randint(0,33) != 0): answer = 'S'
            else: answer = 'P'
    elif (len(him) % 5 == 0):
        # Decide what to do based on the
        # opponent last 3 movements.
        hist = him[-3:]
        # Does he like to block?
        if (hist.count('B') >= 2): answer = 'S'
    print(answer)

සමඟ ධාවනය කරන්න python3 chargerman.py

ට්‍රික්ස්ටර්

ට්‍රික්ස්ටර් සටන් කරන්නේ කෙසේදැයි නොදනී, එබැවින් ඔහු වෙනත් ගුහා මිනිසා ව්‍යාකූල කිරීමට උත්සාහ කරයි.

import sys, math
a = "PPS"
i = 0
if (len(sys.argv) > 1): i = math.floor(((len(sys.argv[1])-1)/2) % 3)
print(a[i])

සමඟ ධාවනය කරන්න python3 trickster.py

අවාසනාවකට මෙන්, acc74 කැපවීමෙන් පසුව , ට්‍රික්ස්ටර් තවදුරටත් සැලසුම් කළ පරිදි ක්‍රියා නොකරයි .


4
එම උපක්‍රම වැඩසටහන නපුරුයි
නෙක්සස්

Ex නෙක්සස් මමත් එසේමය. අවාසනාවට ට්‍රික්ස්ටර් ඩුවල්ස් වල හොඳට වැඩ කරන්නේ නැහැ.
වෙන්ඩෙල්බ්සිල්වා

7

හෝඩෝර්

හෝඩෝර් ඉතා ආක්‍රමණශීලී නොවේ. පහර දීමට හොඳ අවස්ථාවක් නොමැති නම් ඔහු තම පලිහ තුළ රැඳී සිටීමට කැමතියි.

සමඟ සම්පාදනය කරන්න: javac Hodor.javaසහ සමඟ ධාවනය කරන්න:java Hodor

කේතය:

public class Hodor {
    public static void main(String[] args){

        String previousMoves = null;

        //account for no input
        if(args.length == 0){
            System.out.print('S');
            System.exit(0);
        }else{
            previousMoves = args[0];
        }

        //declare variables
        char action = 'S';
        int enemySharpens = 0, enemyPokes = 0, myPokes = 0, mySharpens = 0;
        String[] movesArray = previousMoves.split(",");
        char[] enemyMoves = movesArray[1].toCharArray(), myMoves = movesArray[0].toCharArray();

        //determine enemy sharpness
        for(int i=0; i<enemyMoves.length; i++){
            if(enemyMoves[i] == 'S'){
                enemySharpens++;
            }else if(enemyMoves[i] == 'P'){
                enemyPokes++;
            }
        }

        //block if opponent can poke, else sharpen
        if(enemySharpens - enemyPokes > 0){
            action = 'B';
        }else{
            action = 'S';
        }

        //determine my sharpness
        for(int i=0; i<movesArray[0].length(); i++){
            if(myMoves[i] == 'P'){
                myPokes++;
            }else if(myMoves[i] == 'S'){
                mySharpens++;
            }
        }

        //poke as much as possible if the game is about to end
        if((mySharpens-myPokes) > (100-enemyMoves.length)){
            action = 'P';
        }

        try{
            //sharpen if opponent blocks 2 times in a row and I didn't just sharpen
            if((enemyMoves[enemyMoves.length-1] == 'B') && (enemyMoves[enemyMoves.length-2] == 'B') && (myMoves[myMoves.length-1] != 'S')){
                action = 'S';
            }
            //poke if opponent sharpens twice in a row
            if((enemyMoves[enemyMoves.length-1] == 'S') && (enemyMoves[enemyMoves.length-2] == 'S')){
                action = 'P';
            }
            //poke if the opponent just sharpened/blocked then poked, has a blunt stick, and my stick isn't blunt
            if((enemyMoves[enemyMoves.length-2] != 'P') && (enemyMoves[enemyMoves.length-1] == 'P') && (enemySharpens-enemyPokes == 0) && (mySharpens - myPokes > 0)){
                action = 'P';
            }
        }catch (ArrayIndexOutOfBoundsException e){
            //not enough info
        }

        //poke if we have a sword
        if(mySharpens-myPokes > 4){
            action = 'P';
        }

        System.out.print(action);
    }
}

සංස්කරණය කරන්න: සුළු කේත යාවත්කාලීන කිරීම


මෙම ඉදිරිපත් කිරීම යම් අවස්ථාවක දී යම් ආකාරයක දෝෂයක් හෝ ව්‍යතිරේකයක් විසි කළේය; ඊළඟ වටයේ අත්හදා බැලීම්වලට පෙර එය නිවැරදි කිරීම පිළිබඳව සොයා බැලීමට ඔබට අවශ්‍ය විය හැකිය.
දොරක්නොබ්

1
සමඟ උත්සාහ කරන්න SB,BB. අනෙක් ගුහා භටයන් පළමු වාරයේ වැරදි ලෙස හැසිරෙන විට හෝඩෝර් ද වැරදි ලෙස හැසිරේ.
සිල්වෙස්ටර්

7

සමපේක්ෂන සිල්වෙස්ටර් - පර්ල් 5

සමපේක්ෂන සිල්වෙස්ටර්ට අවශ්‍ය වන්නේ රටා දෙස බැලීමෙන් කඩුව සොයන අයව එළියට ගැනීමට හා ප්‍රතිවාදියා අවහිර වීමට ඉඩ ඇති විට ප්‍රතිවාදියා මුවහත් කර මුවහත් කිරීමට අවස්ථාවක් ඇති විට සිදුරු කිරීමයි. කෙසේ වෙතත්, ඊළඟ පියවරේදී තමා මුවහත් වනු ඇතැයි ඔහු අනුමාන කිරීමට අවස්ථාවක් තිබේ නම් ඔහු එය නොකරනු ඇති අතර අපි මුවහත් කිරීමට තීරණය කළ විට අපි ඊටත් වඩා ප්‍රවේශම් වන්නෙමු.

ප්‍රතිවාදියා නොපැහැදිලි වූ විට ඔහු ආක්‍රමණශීලී වීමට උත්සාහ කළද අවසානයේදී එය .ල රහිත යැයි පෙනෙන විට කඩුවක් බේරා ගැනීමට පටන් ගනී.

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;

## Valid operations
my $SHARPEN = "S";
my $POKE    = "P";
my $BLOCK   = "B";

## It will also print resolution to stderr
my $VERBOSE = 0;

my $first_move = not @ARGV;
my ($me, $you) = split(',', $ARGV[0]) unless( $first_move );

## What do I do?
me_do($SHARPEN, "beginning") if $first_move;
me_do($POKE, "end is near") if  almost_over() || sword($me);
me_do($SHARPEN, "you sword") if !sword($me) && sword($you);
me_do($POKE, "you repeat") if consecutive_sharpens($you) && sharp($me);
me_do(blunt_move(), "you blunt stick") if not sharp($you); 
me_do(aggressive_move(), "me think you sharpen") if sharpen_next($you) && !sharpen_next($me);
me_do($SHARPEN, "me think you block") if you_block_next() && very_little_chance_me_sharpen_next();
me_do($BLOCK, "me have no idea you do");

sub almost_over {
  sharp($me) >= (100 - length($you));
}

sub sharp {
  my $history = shift;
  my $sharp = 0;
  foreach my $s ( split('',$history) ) {
    $sharp++ if( $s eq "S");
    $sharp-- if( $s eq "P" && $sharp > 0);
  }
  return $sharp;
}

sub sword {
  my $me = shift;
  sharp($me) >= 5;
}

sub num_pokes {
  my $me = shift;
  $me =~ s/[^P]//g; #/ SO highlight bug?
  length($me);
}

sub consecutive_sharpens {
  my $you = shift;
  $you =~ m/SS+$/
}

sub sharpen_next {
  my $you = shift;
  $you =~ /([^S]+)S\1S\1$/;
}

sub you_block_next {
  $you =~ /([^B]+B*)B\1B\1$/ || $you =~ /B{4}$/;
}

sub very_little_chance_me_sharpen_next {
  $me !~ /S$/ && ( $me !~ /([^S]+)S\1$/ || $me =~ /^SB+SB+$/ ); 
}

sub blunt_move {
  my $sword_move = sword($me) ? $POKE : $SHARPEN;
  ( $me =~ m/(?:PS){5,}/ || sharp($me)*7 < num_pokes($me) ? $sword_move : aggressive_move() );
}

sub aggressive_move {
  sharp($me)? $POKE : $SHARPEN;
}

sub me_do {
  my ($stick_operation, $reason) = @_;
  my $arg = ( $first_move ? "" : "$me,$you" );
  my $resolution = "$stick_operation me do because $reason ($arg)";
  print "$resolution\n";
  err($resolution);
  exit;
}

sub err {
  my($str) = @_;
  print STDERR "SpeculativeSylwester:$str\n" if $VERBOSE;
}

ලිනක්ස් මත ධාවනය කිරීමට මෙය playerlist.txt හි එක් කරන්න:

perl players/SpeculativeSylwester/SpeculativeSylwester.pl

පහසු ෆිබොනාච්චි - R6RS යෝජනා ක්‍රමය

පළමු පියවරට අමතරව හැරීම ෆිබොනාච්චි අංකයක් වන විට (0 සිට ඇරඹෙන) පහසු ෆයිබොනාච්චි අවහිර වන අතර ඉතිරි කොටස පුරවා කඩුවකින් ජයග්‍රහණය PPSS..කිරීම PSSසඳහා 8 ක් නිමක් නැති අනුක්‍රමයකට ගමන් කරන විට වෙනස් වේ.

#!r6rs
(import (rnrs base)
        (only (rnrs) fold-left display command-line))

(define %SHARPEN "S")
(define %POKE    "P")
(define %BLOCK   "B")

(define (fibonacci? n)
  (let loop ((a 1) (b 1))
    (cond ((> a n) #f)
          ((= a n) #t)
          (else (loop b (+ a b))))))

(define (poke? num-sp)
  (if (< num-sp 8)
      (even? (div num-sp 2))
      (= 2 (mod num-sp 3))))

(define (split-string x)
  (let ((len (div (string-length x) 2)))
    (substring x 0 len)))

(define (num-sp x)
  (fold-left (lambda (a x)
               (if (eqv? x #\B) a (+ a 1)))
               0
               (string->list x)))

(define (advanced-strategy me)
  (cond ((fibonacci? (string-length me)) %BLOCK)
        ((poke? (num-sp me)) %POKE)
        (else %SHARPEN)))

(define (decide args)
  (if (= (length args) 1)
      %SHARPEN
      (advanced-strategy (split-string (cadr args)))))

;; The dirty imperative code:
(display (decide (command-line)))

ධාවනය කිරීම සඳහා ikarus සමඟ ස්ථාපනය කර apt-get install ikarusමෙය playerlist.txt හි එක් කරන්න:

ikarus --r6rs-script players/FacileFibonacci/FacileFibonacci.scm

අධ්‍යයන සිල්වෙස්ටර් - පර්ල් 5

අධ්‍යයන සිල්වෙස්ටර් සමපේක්ෂන සිල්වෙස්ටර්ගේ උපක්‍රමයම භාවිතා කරයි, නමුත් ඔහු වැරදි තේරීමක් කර ඇත්තේ කොතැනද යන්න තීරණය කිරීම සඳහා ඔහු පෙර ක්‍රීඩා දෙස බලයි.

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;

## Valid operations
my $SHARPEN = "S";
my $POKE    = "P";
my $BLOCK   = "B";

## It will also print resolution to stderr
my $VERBOSE = 0;

my $path = $0; # "players/StudiousSylwester/StudiousSylwester.pl";
my $first_move = not @ARGV;
my ($me, $you) = split(',', $ARGV[0]) unless( $first_move );

## What do I do?
me_do($SHARPEN, "beginning") if $first_move;
me_do(consult_history($POKE, "end is near")) if  almost_over() || sword($me);
me_do(consult_history($SHARPEN, "you sword")) if sword($you);
me_do(consult_history($POKE, "you repeat")) if consecutive_sharpens($you) && sharp($me);
me_do(consult_history(blunt_move(), "you blunt stick")) if not sharp($you);
me_do(consult_history(aggressive_move(), "me think you sharpen")) if sharpen_next($you) && !sharpen_next($me);
me_do(consult_history($SHARPEN, "me think you block")) if you_block_next() && very_little_chance_me_sharpen_next();
me_do(consult_history($BLOCK, "me have no idea you do"));

sub almost_over {
  sharp($me) >= (100 - length($you));
}

sub sharp {
  my $history = shift;
  my $sharp = 0;
  foreach my $s ( split('', $history) ) {
    $sharp++ if( $s eq "S");
    $sharp-- if( $s eq "P" && $sharp > 0);
  }
  return $sharp;
}

sub sword {
  my $me = shift;
  sharp($me) >= 5;
}

sub num_pokes {
  my $me = shift;
  $me =~ s/[^P]//g; #/ SO highlight bug?
  length($me);
}


sub consecutive_sharpens {
  my $you = shift;
  $you =~ m/SS+$/
}

sub sharpen_next {
  my $you = shift;
  $you =~ /([^S]+)S\1S\1$/;
}

sub you_block_next {
  $you =~ /([^B]+B*)B\1B\1$/ || $you =~ /B{4}$/;
}

sub very_little_chance_me_sharpen_next {
  $me !~ /S$/ && ( $me !~ /([^S]+)S\1$/ || $me =~ /^SB+SB+$/ );
}

sub blunt_move {
  my $sword_move = sword($me) ? $POKE : $SHARPEN;
  ( $me =~ m/(?:PS){5,}/ || sharp($me)*7 < num_pokes($me) ? $sword_move : aggressive_move() );
}

sub aggressive_move {
  sharp($me)? $POKE : $SHARPEN;
}


sub consult_history {
  my ($suggested_move, $why) = @_;
  my $mylen = length($me);

  # By demanding 5 or more there are 81 (- illegals)
  # different possibilities. Below that and
  # we are shooting in the dark.
  return @_ if( $mylen <= 4 );

  my $override = $suggested_move;
  my @lines = ();
  my %matches      = (P => 0, B=> 0, S=> 0);
  my %match_prefix = (P => 0, B=> 0, S=> 0);
  my $file = "$path.prefix";
  my $sem = "$path.sem";
  my $found_session = 0;

  # Since Judge is running multiple instances at the same time we flock
  open(LOCK, "> $sem") || die ("$path error while open $sem: $!");
  flock(LOCK, 2);

  if( -e $file ) {
    open(FH, $file) || die("$path: error while open $file: $!");

    my $prevyou = substr($you,0,-1);
    while(my $ln = <FH>){
      if ( $ln =~ m/^$me(.).*,$you(.?).*$/ ) {
         # Match that ends here is either a win or a loss depending on my choice
     my $key = ($2 eq "" ? ( $1 eq $POKE ? $SHARPEN : $POKE ) : $2);
     $matches{$key}++;
     $match_prefix{$1}++;
      }
      if( $ln =~ m/^$me,$prevyou$/ ) {
        $found_session++;
    next;
      }
      $found_session++ if( $ln =~ m/^$me.*,$prevyou.*$/ );
      push @lines,$ln;
    }
  }

  my $num_matches = (grep { $matches{$_} != 0 } keys %matches);
  unless( $num_matches || $found_session || $mylen == 5 ) {
    err("WARNING: You have not started this game from the beginning. This will not be a valid outcome! ($me,$you)");
  }

  if( $num_matches == 1 ) {
    my $match_val = (grep { $matches{$_} != 0 } keys %matches)[0];
    if( $match_val eq $BLOCK && !sharp($me)) {
      $override = $SHARPEN;
      $why = "me know u block";
    } elsif ( $match_val eq $SHARPEN ) {
      $override =  aggressive_move();
      $why = "me know u sharpen";
    } elsif ( $match_val eq $POKE && !sword($me) ) { 
      $override = $BLOCK;
      $why = "me know u poke";
    }

  } elsif($num_matches > 1 && $mylen > 6 ) {
    # if the chances are overwelming we are not poked we might as well sharpen
    # if we are wrong here we loose
    if( $matches{$POKE} * 4 < ($matches{$BLOCK}+$matches{$SHARPEN}) && !sword($me)){
      $override = $SHARPEN;
      $why = "me think u block/sharpen";
    }
    # if chances for sharpening is higher than poke/block we go for it with any stick
    if( $matches{$SHARPEN} > 2*($matches{$BLOCK}+$matches{$POKE}) && sharp($me) ) {
      $override = $POKE;
      $why = "me think u sharpen";
    }

    # if the chances for poke is overwelming, we might consider blocking
    if( $matches{$POKE} > 2*($matches{$BLOCK}+$matches{$SHARPEN}) && !sword($me)){
      $override = $BLOCK;
      $why = "me think u poke";
    }
  }

  unless ( $match_prefix{$override} ) {
    open( FH, "> $file") ||     die("$path: error while open $file: $!");
    push @lines, "$me$override,$you\n";
    foreach my $line ( sort @lines ) {
      print FH $line;
    }
  }

  my $stats = join("",map {"$_=>$matches{$_} "} keys %matches);

  if( $override ne $suggested_move ) {
     $why .= ". stats: $stats, original choice: $suggested_move";
  }

  close FH;
  close LOCK;

  return ( $override, $why );
}

sub me_do {
  my ($stick_operation, $reason) = @_;
  my $arg = ( $first_move ? "" : "$me,$you" );
  my $resolution = "$stick_operation me do because $reason ($arg)";
  print "$resolution\n";
  err($resolution);
  exit;
}

sub err {
  my($str) = @_;
  print STDERR "StudiousSylwester:$str\n" if $VERBOSE;
}

ලිනක්ස් මත ධාවනය කිරීමට මෙය playerlist.txt වෙත එක් කරන්න

perl players/StudiousSylwester/StudiousSylwester.pl

අධ්‍යයන සංස්කරණය

$0පර්ල් සමඟ ධාවනය වන විට පර්ල් ස්ක්‍රිප්ටයේ සම්පූර්ණ මාවත නොවීම නිසා ඔබට ඇති වූ ගැටලු මට ප්‍රතිනිෂ්පාදනය කළ නොහැක . මම ඔබේ වෙනස්කම් ද ඇදගෙන ඇති අතර CavemanDuels src හි කිසිදු වෙනසක් මා නොදකින අතර ඔබ වාර්තා කරන ගැටලුවකින් තොරව මම 20+ වාරයක් ධාවනය කර ඇත්තෙමි. මම බියෙන් පටන් ගන්නවා, ඔබ තිර රචනය ක්‍රියාත්මක කළ හැකි වේලාවක ධාවනය කරනවා වෙනුවට එය විස්තාරකයක් ලෙස උපුටා දක්වනු ඇතැයි කියා. ඇත්ත වශයෙන්ම දැන ගැනීමට මට තවත් තොරතුරු අවශ්‍යයි. පරීක්ෂණයක් ලෙස මම මෙය කළ අතර ඔබට එකම ප්‍රති result ලය ලැබේදැයි බැලීමට ඔබට එයම කළ හැකිය:

echo '#!/usr/bin/perl
print "$0\n\n";' > testcmd.pl;
perl ./testcmd.pl;           # outputs ./testcmd.pl
bash -c "perl ./testcmd.pl"; # outputs ./testcmd.pl
bash -c ./testcmd.pl;        # outputs an error since it's not executable
chmod 755 ./testcmd.pl;
./testcmd.pl;                # outputs ./testcmd.pl
bash -c ./testcmd.pl;        # outputs ./testcmd.pl since it's executable

යෝජනා ක්‍රමයට මගේ යන්ත්‍රය සමඟ මා සමඟ සහයෝගයෙන් කටයුතු කිරීමට අවශ්‍ය බවක් නොපෙනේ, එබැවින් මට ෆිබොනාච්චි පරීක්‍ෂා කිරීමට නොහැකි විය. මම එය දිගටම ක්‍රියාත්මක කිරීමට උත්සාහ කරමි, නමුත් ඔබට එය වෙනත් භාෂාවකට පරිවර්තනය කළ හැකි නම් එය ඉතා හොඳ වේ.
දොරක්නොබ්

චිත්රපටය ද වැඩ කරන බවක් නොපෙනේ, මන්ද $0එය bashබාෂ් විධාන රේඛාවකින් (පාලකය විසින් කරන ලද) ඇමතූ විට ය. ඔබට දෘඩ කේත කළ හැකිය players/StudiousSylwester/foo.txt.
දොරක්නොබ්

O ඩෝර්ක්නොබ් මම ස්ථාපනය කරන්නේ කෙසේද යන්න එකතු කර ඇති ikarusඅතර මම මගේ සිතුවිලි $0අධ්‍යයනය සඳහා එකතු කර ඇත්තෙමි .
සිල්වෙස්ටර්

6

කඩුකරු

තියුණු පොල්ලක් අවශ්‍යයි. තියුණු සැරයටියක් ඇත්නම්, සිදුරු කරන්න. මට වේදනාවක් දැනෙන්නේ නැහැ.

program Swordsmith
   implicit none
   integer :: mySharp,ierr,arg_count
   logical :: lExist
   character(38) :: filename = "players/Swordsmith/SwordsmithSharp.txt"

! check argument counts for initialization of storage file
   arg_count = command_argument_count()
   if(arg_count == 0) then
      inquire(file=filename,exist=lExist)
      mySharp = 0
      if(lExist) then
         open(unit=10,file=filename,status='replace')
      else
         open(unit=10,file=filename,status='new')
      endif
      write(10,*) mySharp
      close(10)
   endif

! open, read, & close the file for mySharp
   open(unit=10,file=filename,status='old')
   read(10,*) mySharp
   close(10)

! make decision
   if(mySharp < 5) then
      print '(a1)',"S"
      open(unit=10,file=filename,status='replace')
      mySharp = mySharp + 1
      write(10,*) mySharp
      stop
   endif
   print '(a1)',"P"
end program Swordsmith

ඕනෑම සාමාන්‍ය ක්‍රියාත්මක කළ හැකි ආකාරයටම සුරකින්න swordsmith.f90සහ සම්පාදනය gfortran -o swordsmith swordsmith.f90කරන්න : ./swordsmith.


මෙය සැබෑ ප්‍රතිදානයට පෙර අවකාශයක් (``) මුද්‍රණය කරන බවක් පෙනේ. එය නිවැරදි කරන්නේ කෙසේදැයි මට අදහසක් නැත, එබැවින් මෙම ඉදිරිපත් කිරීම පළමු වටයේ පරීක්ෂණ වලින් බැහැර කිරීමට මට සිදුවේ.
දොරක්නොබ්

එසේම, මම ඔබේ ගොනු මාර්ගය නිවැරදි කර ඇත; වත්මන් වැඩ කරන ඩිරෙක්ටරිය ක්‍රියාත්මක වන විට එය ඔබේ වැඩසටහන නොවේ . ඔහ්, සහ “නව අවස්ථාවකින්” ඔබ අදහස් කරන්නේ “සෑම ක්‍රීඩාවක්ම” නම්, මට එය කළ නොහැක්කේ එයට පාලක වැඩසටහනට විශේෂ ආවරණයක් අවශ්‍ය වන බැවිනි; ඔබට එය ඔබේම කේතයකින් කිරීමට අවශ්‍ය විය හැකිය.
දොරක්නොබ්

O ඩෝර්ක්නොබ්: මම මගේ කේතය යාවත්කාලීන කර ඇත: ප්‍රතිදානය තනි අක්ෂරයකි, එය දැනටමත් පවතින ගොනුවක් පළමු ධාවනයේදී මකා දමයි, සහ ගොනුව ප්ලේයර් නාමාවලියෙහි ඇත.
කයිල් කැනොස්

හරි, ස්තූතියි! මෙම ඉදිරිපත් කිරීම දැන් ප්‍රමුඛ පුවරුවට ඇතුළත් කර ඇත.
දොරක්නොබ්

O ඩෝර්ක්නොබ්: සිසිල්! මම පළමුවෙන් නොවන බව දැනේ. එසේම: මට විශ්වාසයි ෆෝට්රාන් භාවිතා කරන්නන් වැම්පයර්වරුන් හා සමාන බව, එබැවින් මට විශ්වාසයි ඔබ ඉක්මනින් ෆෝට්රාන් හි කේතකරණය ආරම්භ කරන බව! Muahahahaha!
කයිල් කැනොස්

5

රෝගියා බ්ලැක්ස්මිත්

මෙම බොට් එක R හි ලියා ඇත, Rscript PatientBlacksmith.Rඑය අවුලුවාලීමට භාවිතා කරන්න.

args <- commandArgs(TRUE)
if(length(args)){
    input <- strsplit(strsplit(args,split=",")[[1]],"")
    me <- input[[1]]
    opponent <- input[[2]]
    sharpness <- 0
    for(i in seq_along(opponent)){
        if(opponent[i]=="S") sharpness <- sharpness + 1
        if(opponent[i]=="P") sharpness <- sharpness - 1
        }
    out <- ifelse(sharpness>0,"B","S")
    bfree <- me[me!="B"]
    r <- rle(bfree) #run length encoding
    S_sequence <- r$length[r$value=="S"]
    P_sequence <- r$length[r$value=="P"]
    if(!length(P_sequence)) P_sequence <- 0
    if(tail(S_sequence,1)==5 & tail(P_sequence,1)!=5) out <- "P"
}else{out <- "S"}
cat(out)

ප්‍රතිවාදියාගේ තියුණු බව මැනීම: තියුණු වන විට අවහිර කිරීම, වෙනත් ආකාරයකින් මුවහත් කිරීමට කාලය ගන්න. තමන්ගේම තියුණුබව 5 ට ළඟා වූ විට, තියුණු බව නැති වන තුරු සිදුරු කරන්න.


ආදානයක් ලබා නොදුන් විට මෙය කැඩී යයි (එනම් පළමු වාරයේදී); එය නිවැරදි කරන්නේ කෙසේදැයි මම නොදනිමි, එබැවින් පරීක්ෂණයේ පළමු වටයෙන් එය බැහැර කිරීමට මට සිදුවේ.
දොරක්නොබ්

O ඩෝර්ක්නොබ් නිවැරදි කරන ලදි.
ප්ලැනපස්

5

බන්ධනාගාර නීති, හස්කල්

ගුහා කාන්තාව සිතන්නේ ගුහා මිනිසා සහ අනෙකුත් ගුහා මිනිසා කතා කළ යුතු බවත්, සැරයටිය බෙදා ගත යුතු බවත්ය. එහෙත්, හේයි, සටන් කළ යුතු නම්, බන්ධනාගාර නීතිවලට එරෙහිව සටන් කරන්න. ලොක්කා සොයාගෙන පහර දෙන්න.

වයිස්ලීඩර් ඇල්ෆා කේව්මන් දැන්; ගුහා මිනිසා සටන් කළ යුතු බව. අනෙක් ගුහා භටයන් පසුව සටන් කරයි. මගේ ගුහා මිනිසා නැති වුවහොත් කරදර නොවන්න; ඔහුත් කොහොමත් කෙස් ගසයි.

import System.Environment


-- Tell caveman next move

next move
    | end with sharp stick  = poke with (what have)
    | they no poky          = sharpen stick
    | me have sword         = poke with sword
    | soon them have sword  = try poke or sharpen
    | soon have own sword   = fear pokes
    | think them want sword = sharpen stick
    | getting bored now     = sharpen stick
    | otherwise             = block poky stick


-- How fancy techno computer program know?

    where
        end with sharp stick = pokiness my stick >= moves before fight boring
        they no poky  = pokiness their stick == 0
        me have sword = pokiness my stick >= 5
        soon "them" have sword = pokiness their stick == 4
        soon have "own" sword  = pokiness my stick == 4
        try poke or sharpen = if pokiness my stick > 0
                              then poke with stick
                              else sharpen stick
        fear pokes = count 2 (block poky stick) and (sharpen stick)
        think them want sword = pokiness their stick == 3
        getting bored now = those last 2 mine same

        what have
            | me have sword = sword
            | otherwise     = stick



-- Rest not for caveman - only techno computer

        moves before time up = time - (length . fst $ move)

        and   = my
        mine  = my
        my    = fst move
        their = snd move

        before = "before"
        bored  = "bored"
        boring = "boring"
        have   = "have"
        no     = "no"
        now    = "now"
        own    = "own"
        pokes  = "pokes"
        same   = "same"
        sharp  = "sharp"
        them   = "them"
        want   = "want"


fight = 100


main = do
    movesHistoryEtc <- getArgs
    putStrLn . next . basedOn $ movesHistoryEtc


basedOn = movesOfEachCaveman . history

history []    = ""
history (h:_) = h

movesOfEachCaveman "" = ("", "")
movesOfEachCaveman h  = (\(a, b) -> (a, tail b)) . span (/= ',') $ h


sharpened = 'S'
poked     = 'P'
blocked   = 'B'

times m = length . filter (== m)


with  = "WITH"
poky  = "POKY"
sword = "SWORD"
stick = "STICK"

sharpen stick    = "SHARPEN " ++ stick
block poky stick = "BLOCK " ++ poky ++ " " ++ stick
poke with stick  = "POKE " ++ with ++ " " ++ stick


pokiness stick is = foldl countPokiness 0 stick

countPokiness pokyPoints 'P'
    | pokyPoints > 0         = pokyPoints - 1
    | otherwise              = 0
countPokiness pokyPoints 'S' = pokyPoints + 1
countPokiness pokyPoints  _  = pokyPoints


allLast n x xs = all (== x) $ take n . reverse $ xs

those previous n moves same = ((length moves) >= n)
                           && (allLast n (last moves) moves)

count n firstMoves moveHistory lastMove = if allLast n fm moveHistory
                                          then lastMove
                                          else firstMoves
    where fm = head firstMoves

හස්කල් හි ලියා ඇත (ක්‍රියාකාරී ක්‍රමලේඛනය වෙත යන්න!), එබැවින් jailrules.hs ලෙස සුරකින්න , ඉන්පසු සම්පාදනය කරන්න:

ghc prisonrules.hs

මෙසේ ධාවනය කරන්න:

prisonrules [history]

4

මම ඔහුට ජාවා මෑන් යැයි කියමි

compile: javac JavaMan.java
run: java JavaMan SPB,SBB

සටහන: මම කේත ගොල්ෆ් ක්‍රීඩා කිරීමට අදහස් නොකරමි .. නමුත් ඔබ ගොල්ෆ් ක්‍රීඩකයෙකු නම් සහ අවකාශයන් / අමතර රේඛා ඔබේ ඇස්වලට ලේ ගැලීමක් ඇති කරයි නම් .. එය වෙනස් කිරීමට නිදහස් වන්න

public class JavaMan
{
    public static void main(String[] args)
    {
        // input: SPB,SBB
        // me, enemy
        // S: sharpen, P: poke, B: block

        if (args.length == 0)
        {
            System.out.println("S");
        }
        else
        {
            String[] states = args[0].split(",");
            Player me = new Player(states[0].toCharArray());
            Player enemy = new Player(states[1].toCharArray());  //fixed thanks to Roy van Rijn

            if (me.hasSword())
            {
                System.out.println("P");
            }
            else if (!enemy.canPoke())
            {
                if (me.canPoke() && (Math.random() * 95) < states[0].length())
                {
                    System.out.println("P");
                }
                else
                {
                    System.out.println("S");
                }
            }
            else if (enemy.hasSword())
            {
                if (me.canPoke())
                {
                    System.out.println("P");
                }
                else
                {
                    System.out.println("S");
                }

            }
            else if (enemy.canPoke())
            {
                if (me.canPoke())
                {
                    if ((Math.random() * 95) < states[0].length())
                    {
                        System.out.println("P");
                    }
                    else
                    {
                        System.out.println("B");
                    }
                }
                else
                {
                    if ((Math.random() * 95) < states[0].length())
                    {
                        System.out.println("S");
                    }
                    else
                    {
                        System.out.println("B");
                    }
                }
            }
            else
            {
                System.out.println("S");
            }
        }
    }

}

class Player
{
    int sharpLevel;

    public Player(char[] state)
    {
        sharpLevel = 0;
        for (char c : state)
        {
            switch (c)
            {
            case 'S':
                sharpLevel++;
                break;
            case 'P':
                sharpLevel--;
                break;
            case 'B':
                break;
            default:
                System.out.println(c);
            }
        }
    }

    public boolean hasSword()
    {
        return sharpLevel > 4;
    }

    public boolean canPoke()
    {
        return sharpLevel > 0;
    }
}

4
කිං ඔෆ් ද හිල් අභියෝග සඳහා ඉදිරිපත් කිරීම් ගොල්ෆ් කිරීමට අදහස් නොකෙරේ, එබැවින් කරදර නොවන්න. ;)
මාටින් එන්ඩර්

මම එහි නම ජාවා මෑන් ලෙස වෙනස් කර ඇත්තෙමි, මන්ද "කේව්මන්" ප්‍රමුඛ පුවරුවේ සිටීමට තරමක් සාමාන්‍ය ය. ඔබ සමඟ එය හොඳ යැයි සිතමි; එසේ නොවේ නම්, එය වෙනත් දෙයකට වෙනස් කරන්න.
දොරක්නොබ්

1
ආදානයක් ලබා නොදුන් විට මෙය කැඩී යයි (එනම් පළමු වාරයේදී); ඔබට එය හැසිරවිය යුත්තේ කෙසේදැයි මම නොදනිමි, එබැවින් මට එය පළමු වටයේ පරීක්ෂණ වලින් බැහැර කිරීමට සිදුවේ.
දොරක්නොබ්


1
රාජ්‍යය විග්‍රහ කිරීමේදී ඔබට වැරැද්දක් සිදුවී ඇතැයි මම සිතමි, 'මා' සහ 'සතුරා' යන දෙකම එකම පියවරයන් ගනී: ජනපද [0]
රෝයි වැන් රිජන්

4

ගැඹුරු සිතුවිලි, සී

ගුහා කේතය. ගුහා මිනිසා සිතන්න. ගුහා මිනිසා කරන්න.

// DeepThoughts.c
#include <stdio.h>  // Me need for plan
#include <string.h> // Me need for memory

// Me count sharps. If me still here, pokes no work
int is_pointy(char *past){
    int pointy = 0;     // Stick dull
    while(*past){
        switch(*past ++){
            case 'S': pointy ++; break;
            case 'P': if(pointy > 0) pointy --;
        }
    }
    return pointy;
}

// Me brain
int main(int argc, char *argv[]){
    int me_pointy = 0;  // Is 0, stick dull. Is 5, has sword
    int you_pointy = 0; // Same to you
    int me_last;        // Me last plan
    int you_last;       // Same to you
    char *you;          // You past
    int when;           // Time
    int me_plan;        // Me deep thought

    // Me remember
    if(argc > 1){
        you = strchr(argv[1], ',');     // Me find you past in me arg
        *you ++ = 0;
        when = strlen(argv[1]);         // Time is passing
        me_pointy = is_pointy(argv[1]); // Me look at me past
        you_pointy = is_pointy(you);    // Same to you
        me_last = argv[1][when - 1];    // Why me do that?
        you_last = you[when - 1];       // Same to you
    }

    // Me has deep thoughts. Me make plan
    if(me_pointy >= 5) me_plan = 'P';       // Me has sword
    else if(you_pointy == 0) me_plan = 'S'; // Me safe. You stick dull
    else if(when == 1) me_plan = 'P';       // Me shoot first (more thought)
    else if(me_pointy == 1 && when < 42) me_plan = 'B';  // Me try for sharper (deeper thought)
    else if(me_pointy > 0) me_plan = 'P';   // Me stick not dull
    else if(me_last == 'P') me_plan = 'B';  // Me in trouble
    else me_plan = 'S';                     // Me cross toes

    // Me do plan
    putchar(me_plan);
    return 0;
}

මම පරීක්ෂණ කරන්න. තවත් සිතුවිලි වඩා හොඳය.


1
ගුහා මිනිසාගේ නම් සහ අදහස් සඳහා +1: P එසේම, හොඳ වැඩසටහන c:
cat

3

නයිජල්

නයිජල් යනු ඉවසිලිවන්ත, ආරක්‍ෂිත පැරණි ගුහා මිනිසෙකි, ඔහු ප්‍රහාරයෙන් සියල්ලන්ම පිටතට යෑමට වඩා උපායශීලී වනු ඇත.

එය PHP පිටපතක්, අමතන්න php nigel.php

<?php
// Seed the random number generator
srand(time());

// Simple function output chosen move
function move($m)
{
    echo $m;
    echo "\n";
    exit;
}

// Make stick sharp if first move
if (sizeof($argv) == 1)
    move("S");

// Grab the list of moves
$moves = explode(",", $argv[1]);    
$mySharpness = 0;
$opSharpness = 0;

// Loop through all previous moves and calculate sharpness
for ($i=0; $i<strlen($moves[0]); $i++)
{
    $myMove = substr ($moves[0], $i, 1);
    $opMove = substr ($moves[1], $i, 1);
    if ($myMove == "S")     $mySharpness++;
    if ($opMove == "S")     $opSharpness++; 
    if ($myMove == "P" && $mySharpness > 0)     $mySharpness--;
    if ($opMove == "P" && $opSharpness > 0)     $opSharpness--;     
}

// We somehow have a sword.. ATTACK!
if ($mySharpness > 4)
    move("P");

// Opponent is blunt, guarenteed upgrade!
if ($opSharpness < 1)
    move("S");          

// If we're sharp, either block or poke, unless OP is near a sword
if ($mySharpness > 0)
{
    // Oppenent is halfway to a sword.. ATTACK!
    if ($opSharpness > 2)
        move("P");  

    if (rand(0,1) == 0)     move("P");
    else                    move("B");
}

// If we're blunt, either sharpen or block
else
{
    if (rand(0,1) == 0)     move("S");
    else                    move("B");  
}

?>

3

අයිච්මෝෆොබික් - ලුවා

ඔහු ඉඳහිට ඔබට පහර දෙයි, නමුත් සමහර සැරයටිය ඉතා තියුණු වන තුරු පමණි. මෙය සිදු වූ විට, ඔහු කලබල වී භ්‍රෑණ තත්වයට පත්වේ.

if arg[1] == nil then
  response = "S"
elseif not arg[1]:match('SSSSS') == nil then
  --PANIC
  response = "B"
else  
  --Minds his own business and goes where he pleases
  math.randomseed(os.time())
  local rand = math.random();

  response = rand > 0.6 and "P" or "S"
end

print(response)

මෙය සමඟ ධාවනය කරන්න:

lua aichmophobic.lua


2
ඔබේ ප්‍රතිදානය ලොකු අකුරුවලින් විය යුතුය; මම ඔබ වෙනුවෙන් එය සවි කර ඇත්තෙමි. (එසේම, මම මෙම ඉදිරිපත් කිරීමේ නම දහසක් පමණ වැරදියට ලියා ඇත .: P)
දොරක්නොබ්

3

බොබ් ගුහා

බොබ් ගුහා යනු ඔහුගේ ගුහාවේ සිටින ඉතා දක්ෂ පුද්ගලයෙකි. ඔහු එක් අතකින් ගණන් කිරීමට ඉගෙනගෙන ඇත (අනෙක් අත ඔහුගේ සැරයටිය අල්ලාගෙන සිටී). ඔහු මෙම ගල් යුගයේ ඔලිම්පික් උළෙල ගැන දන්නා අතර එයට සහභාගී වීමට අවශ්‍ය විය.

ඔහුගේ ප්‍රධාන උපායමාර්ගය වන්නේ ඔහුට හොඳ තියුණු දණ්ඩක් හෝ අනෙක් ගුහා මිනිසාට තියුණු එකක් ඇති වන තුරු ඔහුගේ සැරයටිය අවහිර කර මුවහත් කිරීමයි. මේ අවස්ථාවේ දී බොබ් ගුහා ඔහුට පහර දීමට උත්සාහ කරයි!

import java.util.Random;

public class BobCaves {

    public static void main(String[] args) {
        int mySharpness = 0;
    int otherSharpness = 0;

    //Boc counts
    if (args.length > 0) {
        String[] ss = args[0].split(",");
        mySharpness = howSpiky(ss[0]);
        otherSharpness = howSpiky(ss[1]);
    }
    // Bob thinks!
    Random rn = new Random();
    if (mySharpness == 0 && otherSharpness == 0){
        System.out.println( "S");
    }
    if (otherSharpness == 0 && mySharpness < 5 && mySharpness > 0){
        if (rn.nextBoolean()){
            System.out.println("P");
        } else {
            System.out.println("S");
        }
    } 

    if (mySharpness >= 5 || (otherSharpness >= 2 && mySharpness > 0)) {
        System.out.println("P");
    }

    if (rn.nextInt(5) > 3) {
        System.out.println("S");
    } 

    System.out.println("B");
    }

    private static int howSpiky(String s1) {
        int count = 0;
        char[] c1 = s1.toCharArray();
        for (int i = 0; i < c1.length; i++) {
        if (c1[i] == 'S') {
                count++;
            } else if (c1[i] == 'P'){
                count --;
            }
        }
        return count;
    }

}

සමඟ සම්පාදනය කර javac BobCaves.javaධාවනය කරන්නjava BobCaves

සංස්කරණය කරන්න: කිසියම් වාරණයක් ඇති විට බොබ් දැන් ගණන් ගනී! ( මිකී මවුස්ට ස්තූතියි ). අනෙක් ගුහා මිනිසාගේ සැරයටිය නොපැහැදිලි වූ විට ඔහු තම සැරයටිය මුවහත් කරයි.

2 වන සංස්කරණය: වැඩි දියුණු කළ ගණන් කිරීමේ ක්‍රමය (මිකීට නැවතත් ස්තූතියි).

3 වන සංස්කරණය: බොබ් තරමක් ආක්‍රමණශීලී කිරීම.


2
පොබ්ගේ ගණන් කිරීමේ බලපෑම බොබ්ට අමතක වේ: තමන්ගේම සැරයටියේ තියුණු බව අවහිර කරන්න. S හි "S" තුනක් මධ්යන්ය සැරයටියක් 3 ගුණයක් තියුණුය. S හි ඇති සෑම "P" වලින්ම අදහස් නොකෙරේ. හහ් හහ් හහ් ... "පී" ගුහා මිනිසා විහිළුවක් ...
මිකී මවුස්

Ike මයිකිමූස් බොබ් එකඟ වෙයි. බොබ් මායාකාරිය වෙත ගොස් ඔහුගේ තාක්ෂණය දියුණු කරනු ඇත. බොබ් කෘත ful වෙනවා!
Averroes

1
මායාකාර වෛද්‍යවරයා බොබ්ට හොඳට උගන්වයි. නමුත් ඔහුට අමතක වී ඇත්තේ Poke: Poke තත්වය. එලෙසම මොට වන්න. ප්‍රතිවාදියාගේ පියවර සලකා බැලීමට බොබ්ට අවශ්‍ය නැත. බොබ් පොක් නම්, සැරයටිය බොඳ වන්න. එක්කෝ නොපැහැදිලි: ප්‍රතිවාදියාගේ සිදුර, ප්‍රතිවාදියාගේ කොටස මත හෝ ප්‍රතිවාදියාගේ හිස මත. ප්‍රතිවාදියාගේ හිස මත නම්, බොබ් ජයග්‍රහණය කර ගුහාව වටා නටන්න පුළුවන්.
මිකී මවුස්

1
Ike මයිකිමූස් බොබ් ගණන් කරන ආකාරය දනී. බොබ්ට කියවීමට ඉගෙන ගත යුතුය. නැවත ස්තූතියි!
Averroes

3

ග්‍රන්ට්

ග්‍රන්ට් ආරක්ෂිතයි. ග්‍රන්ට් වෙනත් ගුහා භටයින් ඒවා විදින ආකාරය දැන ගැනීමට විශ්ලේෂණය කරයි. එවිට ඔහු ඒවා ඇසට යොමු කරයි. ග්‍රන්ට් ලස්සන ගුහා මිනිසෙක් නොවේ.

public class Gruntt {

public static void main(String[] args) {
    System.out.println(whatToDo(args));
}

private static String whatToDo(String[] args){
    int mySharpness = 0;
    int otherSharpness = 0;

    if (args.length > 0) {
        String[] ss = args[0].split(",");
        mySharpness = howSpiky(ss[0]);
        otherSharpness = howSpiky(ss[1]);
    } else {
        return "S";
    }

    if (mySharpness >= 5){
        return "P";
    }

    String res = wowoo(args[0].split(",")[1]);
    if ("P".equals(res) && mySharpness > 0) {
        return "P";
    } else if ("P".equals(res) && mySharpness == 0) {
        return "S";
    } else if ("S".equals(res) && !args[0].split(",")[0].endsWith("S")) {
        return "S";
    }

    if (otherSharpness == 4 && !args[0].split(",")[0].endsWith("P")){
        return "P";
    }

    if (otherSharpness == 0){
        return "S";
    }

    return "B";

}

private static int howSpiky(String s1) {
    int count = 0;
    char[] c1 = s1.toCharArray();
    for (int i = 0; i < c1.length; i++) {
    if (c1[i] == 'S') {
            count++;
        } else if (c1[i] == 'P'){
            count --;
        }
    }
    return count;
}

private static String wowoo(String s){
    String s1 = "";
    String s2 = "";

    if (s.length() >= 4){
        s1 = s.substring(s.length() - 4);
    }

    if (s.length() >= 3){
        s2 = s.substring(s.length() - 3);
    }

    if ("SPSP".equals(s1)){
        return "P";
    } else if ("SSS".equals(s2)){
        return "P";
    } else if ("BBBB".equals(s1)){
        return "S";
    } else if ("SBSB".equals(s1)){
        return "P";
    }

    return null;
}

}

සමඟ සම්පාදනය කර javac Gruntt.javaධාවනය කරන්නjava Gruntt


මෙය ArrayOutOfBoundsExceptionපළමු වාරයේ දී විසි කරන අතර සමහර විට එය වෙනත් හැරීම් මත බහුවිධ ක්‍රියා කරයි.
දොරක්නොබ්

O ඩෝර්ක්නොබ් ඕප්ස්! ස්ථාවර, ස්තූතියි!
Averroes

3

එය කුරුල්ලෙක් ද? එය ගුවන් යානයක් ද? එය RegExMan!

ඔහු ඔබේ සුපිරි කම්මැලි අනුපිළිවෙල විශ්ලේෂණය කිරීමට උත්සාහ කරන්නේ ඔහුගේ විශේෂ ප්‍රාථමික රෙජෙක්ස් බලයෙනි!

#!/usr/bin/env python
import sys, re

def whatAmIDoing(opnHist, meSharp, opnSharp) :

    match = re.search(r"([PSB]{3,})\1$", opnHist)    ### Super RegEx ftw!

    if meSharp >= 5 :
        return "P"
    if opnSharp == 4 and meSharp > 0 :
        return "P"
    if match :
        opnStrat = match.group()
        if opnStrat[0] == "S" :
            if meSharp > 0 :
                return "P"
            else :
                return "S"
        elif opnStrat[0] == "B" :
            return "S"
    if opnSharp <= 0 :
        return "S"
    return "B"

try :
    hist = sys.argv[1].split(",")
    sharp = map(lambda h : h.count("S") - h.count("P"), hist)
    answer = whatAmIDoing(hist[1], *sharp)
except Exception :
    answer = "S"
finally :
    print(answer)

පයිතන් 2.7 හි ලියා ඇත, සමඟ ධාවනය කරන්න python RegExMan.py [history]


3

සිසිලියන්

නමුත් එය ඉතා සරලයි! මා කළ යුතුව ඇත්තේ වෙනත් ගුහා මිනිසා ගැන මා දන්නා දෙයින් දිව්‍යමය දෙයක් පමණි: ඔහු අවහිර කිරීම, මුවහත් කිරීම හෝ ඇණ ගැසීම වැනි ගුහා මිනිසාද? දැන්, දක්ෂ ගුහා මිනිසෙක් විදිනවා හෝ අවහිර කරයි, මන්ද ඔහු දැන සිටියේ මහා මෝඩයෙකු පමණක් මුවහත් කර පහර දීමට නිරාවරණය වන බවය. මම මහා මෝඩයෙක් නොවේ, එබැවින් මට පැහැදිලිවම මුවහත් කළ නොහැකිය. නමුත් අනෙක් ගුහා මිනිසා දැන සිටිය යුතුය, මම මහා මෝඩයෙකු නොවන අතර, එය ගණන් ගනු ඇත, එබැවින් මට පැහැදිලිවම සිදුරු කිරීමට හෝ අවහිර කිරීමට නොහැකිය!

සමඟ ධාවනය කරන්න:

javac Sicillian.java
java Sicillian

කේතය:

public class Sicillian {

    public static void main(String[] args) {

        if (args.length == 0) System.out.println("S");
        else {
            //get and analyze history
            String[] history = args[0].split(",");
            Caveman vizzini = new Caveman(history[0].toCharArray());
            Caveman fool = new Caveman(history[1].toCharArray());
            Think divine = new Think(history[0].toCharArray(),history[1].toCharArray());

            //The Sicillian always thinks and makes a logical decision before acting...
            char onlyAFool = divine.clearly(vizzini.getSharpness(),fool.getSharpness());

            //Never go in against a Sicillian when death is on the line!
            if(onlyAFool == 'S') {
                if(!vizzini.weaponless()) poke();
                else sharpen();
            }
            else if(onlyAFool == 'P') {
                if(vizzini.hasSword()) poke();
                else block();
            }
            else if(onlyAFool == 'B') sharpen();

            else {          // Inconceivable!

                //if he's a sharpener, poke him where it hurts!
                if(fool.isSharpener()) {
                    if(vizzini.getSharpness() >= 2) poke();  //don't ever go weaponless, else you give him the advantage
                    else sharpen();
                }               
                //if he's a blocker, get sword and break through his defense
                else if(fool.isDefensive()) {
                    if(vizzini.hasSword()) poke();
                    else sharpen();
                }
                // fool doesn't have a disposition to do anything in particular
                else {
                    //he could be sharpening and blocking to get a sword in which case his sharpness will be higher
                    //or a random, which will average a lower sharpness
                    if (fool.getSharpness() <= 2) { //assume random
                        if(vizzini.hasSword()) poke();
                        else if(fool.weaponless()) sharpen();
                        else block();
                    }
                    else {
                        if(vizzini.hasSword()) poke();
                        else if(vizzini.getSharpness() > fool.getSharpness()) sharpen();    //we can win race to sword
                        else if(vizzini.getSharpness() >= 2 || (!vizzini.weaponless() && fool.onEdge())) poke();
                        else sharpen();
                    }
                }
            }           
        }
    }   //end of main

    private static void poke() {
        System.out.println("P");
    }
    private static void block() {
        System.out.println("B");
    }
    private static void sharpen() {
        System.out.println("S");
    }
}
class Think {
    private char[][] cleverman = new char[6][6];    //tracks what the enemy does in a particular situation 
    private int mySharpness;
    private int enemySharpness;
    public Think(char[] myAction, char[] enemyAction) {
        //init variables
        mySharpness = 0;
        enemySharpness = 0;

        for(int i = 0; i < myAction.length; i++) {
            //remember what enemy did last time
            cleverman[mySharpness][enemySharpness] = enemyAction[i];
            //System.out.println("When I was at ("+mySharpness+") and he was at ("+enemySharpness+") he did ("+enemyAction[i]+")");

            //calculate my sharpness
            if(myAction[i] == 'S') mySharpness++;
            else if(myAction[i] == 'P') mySharpness--;
            if(mySharpness < 0) mySharpness = 0; //ensure multiple pokes don't create a negative sharpness
            //calculate my enemy's sharpness
            if(enemyAction[i] == 'S') enemySharpness++;
            else if(enemyAction[i] == 'P') enemySharpness--;
            if(enemySharpness < 0) enemySharpness = 0; //ensure multiple pokes don't create a negative sharpness
        }   
    }
    public char clearly(int myAction, int enemyAction) {
        if(myAction > 5) myAction = 5;
        if(enemyAction > 5) enemyAction = 5;
        return cleverman[myAction][enemyAction];
    }
}
class Caveman {
    private int sharpness;
    private int disposition;    //Finite State Machine: how inclined the caveman is toward blocking (0) or sharpening (4)
    public Caveman(char[] action) {
        sharpness = 0;
        disposition = 1;        //assume a slightly defensive disposition
        for (int i = 0; i < action.length; i++) {
            if(action[i] == 'S') {
                sharpness++;
                disposition++;
            }
            else if(action[i] == 'P') sharpness--;
            else disposition--;                     //blocking
            if(sharpness < 0) sharpness = 0; //ensure multiple pokes don't create a negative sharpness
            if(disposition > 4) disposition = 4;
            else if(disposition < 0) disposition = 0;
        }
    }
    public int getSharpness() {
        return sharpness;
    }
    public boolean weaponless() {
        return sharpness == 0;
    }
    public boolean hasSword() {
        return sharpness >= 5;
    }
    public boolean onEdge() {
        return sharpness == 4;
    }
    public boolean isDefensive() {
        return disposition == 0;
    }
    public boolean isSharpener() {
        return disposition == 4;
    }
    public int getDisposition() {
        return disposition;
    }
}

3

bash-magnon

Bash-magnons ශක්තිමත් ලෙස ගොඩනඟා ඇති අතර බලවත් විය. ශරීරය සාමාන්‍යයෙන් ශක්තිමත් මාංශපේශී සහිත බරින් යුක්ත විය. නියැන්ඩර්තාල් වල මෙන් බෑවුමට වඩා නළල තරමක් කෙළින් වූ අතර සුළු බ්‍රව්රිජ් පමණක් විය. මුහුණ කෙටි හා පළල් විය. නිකට කැපී පෙනුණි. මොළයේ ධාරිතාව cub න සෙන්ටිමීටර 1,600 ක් (අඟල් 98 ක්) වූ අතර එය නූතන මිනිසුන්ගේ සාමාන්‍යයට වඩා විශාලය. කෙසේ වෙතත්, මෑත කාලීන පර්යේෂණවලින් පෙනී යන්නේ වෙනම තනතුරක් ලබා ගැනීම සඳහා ඊනියා "බාෂ්-මැග්නොන්" හි භෞතික මානයන් නූතන මිනිසුන්ට වඩා ප්‍රමාණවත් නොවන බවයි.

මට මොළයක් තියෙනවා, මට මතකයි.

මෙය ස්වයං ක්‍රියාත්මක කළ හැකි ක්‍රියාවකි ./bash-magnon.sh

#!/bin/bash

function min () {
 [[ $1 -gt $2 ]] && echo $2 || echo $1
}

function max () {
[[ ${1%% *} -gt ${2%% *} ]] && echo $1 || echo $2
}

declare -A brain
declare -i C S P B me he
he=0
me=0
C=0
S=0; B=0; P=0

left=${1%%,*}
right=${1##*,}
while  : 
do

    [[ "${right:$C:1}" ]] && brain[$he$me]=${right:$C:1}
    case "${left:$C:1}${right:$C:1}" in
    BB) true;;
    BP) ((he--));;
    BS) ((he++));;
    PP) ((he--)); ((me--));;
    PB) ((me--));;
    PS|SP) exit;;
    SB) ((me++));;
    SS) ((me++)); ((he++));;
    "") break;;
    esac
    me=$(max 0 $me)
    me=$(min 9 $me)
    he=$(max 0 $he)
    he=$(min 9 $he)
    ((C++))
done

[[ $me$he =  *[5-9] ]] && ((P+=2))
[[ $me$he =  [5-9]* ]] && ((P+=2))
[[ $me$he =  [1-9]0 ]] && ((P+=2))
[[ $me$he =  00 ]] && ((S+=2))
[[ $me$he =  [1-4]4 ]] && ((P+=2))
[[ $me$he =  0[1-4] ]] && ((S+=1))
[[ $me$he =  0* ]] && ((B+=1))

case "${brain["$he$me"]}" in 
S) ((P+=2));;
B) ((S+=2));;
P) ((B+=2));;
*) ((B++));;
esac

set $(max "$B B" "$(max "$P P" "$S S")" )
echo $2

1+ ඔබට පැහැදිලිවම රැකියාව සඳහා නිවැරදි මෙවලමක් ඇති අතර ඔබේ ගුහා මිනිසුන්ගේ නම් තරමක් විනෝදජනක ය :) (මම පෞද්ගලිකව මාළු වලට වඩා කැමතියි)
සිල්වෙස්ටර්

Yl සිල්වෙස්ටර් ස්තූතියි එය මගේ පළමු +1. මම මුලින්ම උත්සාහ කළේ හෝමියෝස්ටැටික් ස්වයංක්‍රීය යන්ත්‍රයක් සෑදීමෙන් පළමු සයිබර්නෙටික් විද්‍යා its යාට එහි සමබරතාවය දැනෙන දෙයින් දේවානුභාවයෙන්, පසුව මම එය අත්හැර බාෂ් පිටපතක් සෑදුවෙමි.
එමානුවෙල්

2

PokeBackBot

PokeBot වෙතින් සරලව අනුවර්තනය කරන ලද්දේ:

puts 'SBPB'[(ARGV.shift || ',').split(',', 2)[0].length % 4]

සමඟ ධාවනය කරන්න ruby pokebackbot.rb.

මෙය ඊළඟ සරලම උපාය මාර්ගය භාවිතා කරන අතර පහර දීමට පෙර එක් වටයක් සඳහා "ඉවසීමෙන්" අවහිර කරයි.


3
Et පීටර් ටේලර් මම කියවූයේ ප්‍රතිවාදියාගේ ඇඟිලි සලකුණු මත පදනම්ව මගේ උපාය වෙනස් කිරීමට ඉඩ නොදෙන බවය. මගේ ඉදිරිපත් කිරීම මගින් තවත් එක් ඉදිරිපත් කිරීමක් පමණක් පරාජය කළ හැකි නම්, එය අනෙක් ඉදිරිපත් කිරීම් ලකුණු වලට සැබවින්ම බලපාන්නේ නැත, සහ මගේ ඉදිරිපත් කිරීම බොහෝ දුරට නරක වනු ඇත. තව දුරටත්, එක් ඉදිරිපත් කිරීමක් පමණක් තිබේ නම් සහ දෙවැන්න ලියා තිබේ නම්, දෙවැන්න පළමු එක පරාජය කිරීමට ඉඩ ඇත (එසේ නොමැතිනම් කරදර වන්නේ මන්ද) - එය පමණක් “වෙනත් වැඩසටහනක් සඳහා විශේෂිත” ලෙස සුදුසුකම් ලබන්නේද? මගේ SPSබෝට්ටුව ආරම්භ වන ඕනෑම බොට් එකක් පරාජය කරනු ඇත (එය සාධාරණ යැයි පෙනේ), නමුත් මේ දක්වා PokeBot එකම විය.
මාටින් එන්ඩර්

2

කඩුව මාස්ටර්

පයිතන් 3.4 හි ලියා ඇත (පයිතන් 3.x සමඟ ක්‍රියා කරයි)

හැකි ඉක්මනින් කඩුවක් ලබා ගැනීමට උත්සාහ කරන නමුත් ඔහුට පහර දීමට අවස්ථාවක් ඇත්නම් පහර දෙයි (තියුණුබව> 0) සහ සතුරාටද එය රිදවිය හැකිය (සතුරාගේ තියුණුබව> 0).
අවහිර කිරීම් තියුණු බවක් නොමැති නම් සහ සතුරාට පහර දිය හැකිය.

ආරම්භ කරන්න:

python3 swordmaster.py MOVES

(ඔබ එය එසේ සුරකිනු ඇතැයි උපකල්පනය කර ඇත swordmaster.py)

ඉක්මන් හා කැත කේතය:

import sys, random
dg = False
if len(sys.argv) > 1:
    ow,ot = sys.argv[1].split(',')
else:
    ow = ot = ""
def gs(m):
    ow = 0
    ot = 0
    i = 0
    ms = m[0]
    mo = m[1]
    for _ in mo:
        if ms[i] == 'S':
            ow += 1
        elif ms[i] == 'P' and mo[i] in ['P','B']:
            ow -= 1
        if mo[i] == 'S':
            ot += 1
        elif mo[i] == 'P' and ms[i] in ['P','B']:
            ot -= 1
        if dg:
            print("Own: {}, Other: {}".format(ow,ot))
        i += 1
    return [ow, ot]

def sm(sh):
    if (type(sh) != list) and dg:
        raise ValueError('Invalid sh type.')
    ow, ot = sh
    if ow >= 5:
        ret = 'P'
    elif ow >= 0 and ot == 0:
        ret = 'S'
    elif ow > 0 and ot > 0:
        ret = 'P'
    elif ow == 0 and ot > 0:
        ret = 'B'
    else:
        ret = random.choice(['S','B','P']) #Should not happen
    return ret

if __name__ == "__main__":
    print(sm(gs([ow,ot])))

( නිදොස් කිරීමේ පණිවිඩ සක්‍රීය කිරීමට සකසා dgඇත True)


1
ඉඟියක්: කිසිවිටෙකත් එය ම සටන් ඉඩ - එය සමඟ සම්පූර්ණ වැඩසටහනම අඩපණ වෙයි S, P, S, P...
chill0r

මෙය මගේත් සිදු වන බව මට පෙනී ගියේය. ඔබ ඉතිහාසය පරීක්ෂා කර හෝ අහඹු ලෙස භාවිතා නොකරන්නේ නම්, ඔබ චක්‍රයකට කොටු වීමට බැඳී සිටී.
ෆරාප්

2

FoolMeOnce.py

පළමු ද්වන්ධ සටන සඳහා එක් එක් ක්‍රීඩකයාගේ චලනයන් සුරකින්න, ඉන්පසු එකම චලනයන් සමඟ නැවත ධාවනය කරන්න. සතුරාගේ ඇල්ගොරිතම අවිධිමත් නම්, අපට එකම ප්‍රති come ලය පුරෝකථනය කළ හැකි අතර පහර දිය හැක්කේ අප ජයග්‍රහණය කරන බව දැනගත් විට පමණි.

import os
import sys
import random

def getLastMove(player, turn):
    path = 'players/FoolMeOnce/'+player+str(turn)+'.txt'
    if os.path.isfile(path):
        with open(path, 'r') as f:
            return f.read()
    else:
        return 'nofile'

def sharpness(history):
    sharpness = 0
    for c in history:
        if c is 'S':
            sharpness+=1
        elif c is 'P' and sharpness > 0:
            sharpness-=1
    return sharpness

def takeTurn(choice, history, turn):
    print(choice)
    with open('players/FoolMeOnce/me'+str(turn)+'.txt', 'w') as f:
        f.write(choice)
    #also record their last choice
    choice = history[-1]
    with open('players/FoolMeOnce/them'+str(turn)+'.txt', 'w') as f:
        f.write(choice)

#if its the first turn, always sharpen
if(len(sys.argv) == 1):
    print('S')

else:
    history = sys.argv[1].split(',')
    meSharp = sharpness(history[0])
    themSharp = sharpness(history[1])
    turn = len(history[0])

    #read opponents move and our move for this turn from last duel
    them = getLastMove('them', turn);
    me = getLastMove('me', turn);

    #if this is first duel, fool me once
    if(them is 'nofile' or me is 'nofile'):
        if themSharp is 0 and meSharp >0:
            takeTurn(random.SystemRandom().choice('PS'), history, turn)
        else:
            takeTurn('B', history, turn)

    #if we could have played a winning move, do it. otherwise do what we did last time
    elif(them is 'S' and meSharp > 0):
        takeTurn('P', history, turn)
    else:
        takeTurn(me, history, turn)

පයිතන් 3 හි ලියා ඇති බැවින් බොහෝ විට ඔබට python3 FoolMeOnce.py භාවිතා කිරීමට සිදුවනු ඇත . පළමු වටයේ දී, අපට හිස් නූලක් හෝ කොමාවක් ලැබේදැයි මට විශ්වාස නැත, එබැවින් යම් යම් වෙනස් කිරීම් අවශ්‍ය විය හැකිය.


මම ඔබේ ගොනු මාර්ගය සවි කර ඇත්තෙමි - වත්මන් වැඩ කරන නාමාවලිය ඔබේ වැඩසටහන නොවේ.
දොරක්නොබ්

CavemanDuel පරීක්ෂක සමඟ සෙල්ලම් කරන අතරතුර, මම වැඩිපුර නූල් භාවිතා කරන්නේ නම් FoolMeOnce වඩා හොඳ ලකුණු ලබා ගන්නා බව මම දුටුවෙමි (මම 4 ට එරෙහිව නූල් 16 ක් පරීක්ෂා කළෙමි). නූල් 4 ක් සමඟ එය ලකුණු 25 ක් ද 16 ක් සමඟ ඩොලර් 34 ක් ද ලබා ගනී.
වෙන්ඩෙල්බ්සිල්වා

අමුතුයි, ඇයි කියලා මම දන්නේ නැහැ.
tzazy
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.