D&Dキャラクターの能力スコアを転がす


18

Dungeons and Dragonsでは、キャラクターの最も重要な属性のいくつかは能力スコアです。6つの能力に対して、6つの能力スコアがあります。能力は、強さ、器用さ、憲法、知性、知恵、カリスマです。

キャラクターのスコアを決定するとき、私は次の手順を使用します:4d6をロールし、最も低いものを任意の順序でドロップします。これが意味することは、4つのサイコロを振って、最低の結果を無視し、残りの3を合計することです。これは6回行われます。結果の番号は、私が好きな方法で能力に割り当てられます。

能力にスコアを割り当てるために使用するシステムは、キャラクターのクラスに応じてキャラクターの最も重要なスキルに最高スコアを割り当て、誰もが憲法を必要とするため、2番目に高いスコアを憲法に割り当て、他の4つのスコアを任意に割り当てます。

さまざまなクラスで最も重要なスキルの表を次に示します。

Bard - Charisma
Cleric - Wisdom
Druid - Wisdom
Fighter - Stregth
Monk - Wisdom
Paladin - Charisma
Rogue - Dexterity
Sorcerer - Charisma
Wizard - Intelligence

課題:(入力として)キャラクターのクラスの最初の文字(大文字)を提供します。上記のようにアビリティスコアをロールし、アビリティに割り当ててから、強さ、器用さ、体質、知性、知恵、カリスマの順に出力してほしい。

例:

Input: R
Rolls: 4316 3455 3633 5443 2341 6122
Scores: 13 14 12 13 9 10
Ordering: Highest goes to dexterity. Second goes to Constitution.
Output: 13 14 13 12 9 10
or
Output: 9 14 13 10 12 13
or etc.

出力は、数字が明確に区切られた適切な順序で任意の形式で提供されます。

バイト単位の最短コードが優先されます。標準的な抜け穴は禁止されています。

回答:


6

CJam、43 41 40バイト

{6a4*:mr$0Zt:+}6*]$2m<"FRXWCDM"r#4e<3e\p

1バイトのゴルフをしてくれた@ Sp3000に感謝します。

CJamインタープリターでオンラインで試してください。

使い方

{             }6*                       e# Repeat 6 times:
 6a4*                                   e#   Push [6 6 6 6].
     :mr                                e#   Replace each six with a pseudo-randomly
                                        e#   generated integer in [0 ... 5].
        $                               e#   Sort the results.
         0Zt                            e#   Replace the lowest result by 3.
            :+                          e#   Add all four integers
                ]                       e# Wrap the 6 generated integers in an array.
                 $                      e# Sort.
                  2m<                   e# Rotate 2 units to the left to assign the
                                        e# second highest result to Constitution.
                     "FRXWCDM"          e# Push that string.
                              r#        e# Find the index of the input.
                                        e# The string doesn't contain B, P or S, so
                                        e# those push -1.
                                4e<     e# Truncate the index at 4. This way, C, D
                                        e# M all push 4.
                                   3e\  e# Swap the integer at that index with the
                                        e# one at index 3, i.e., the highest one.
                                      p e# Print.

6

Python 3、137バイト

from random import*
S=sorted
*L,c,h=S(3+sum(S(map(randrange,[6]*4))[1:])for _ in[0]*6)
L[:"FRW BPS".find(input())]+=h,
L[:2]+=c,
print(L)

例えば、整数のリスト出力[14, 9, 13, 12, 12, 13]のためにF

入力文字から割り当てへのマッピングは驚くほど素晴らしいことが判明しました。まずL、最下位の4つのロールを含めることから始め、その後に挿入します

  • 入力に基づいた正しい位置への最高のロール、そして
  • 憲法の2番目に高いインデックス2にロールインします。

各入力について、最高のロールに必要なインデックスは次のとおりです。

Index    Ability          Input(s)
----------------------------------
0        Strength         F
1        Dexterity        R
2        Intelligence     W
3        Wisdom           CDM
4        Charisma         BPS

驚くべきことに、これだけが必要"FRW BPS".find(input())です。なぜなら:

  • FRW 期待どおりに機能し、それぞれのインデックスを与え、
  • CDM存在しないので、find得られる-1、4要素のリストのインデックス3であり、そして
  • BPS それぞれ4、5、6を指定しますが、最後に要素を追加できるだけなので、オーバーシュートしても問題ありません。

1

J、100 97バイト

(0;0,b)C.^:(b>0)(0;1 2)C.\:~+/"1]1}."1/:~"1]1+?6 4$4$6[b=.('BCDFMPRSW'i.1!:1[1){5 4 4 0 4 5 1 5 3

入力を受け取ります STDIN


プロローグがjeしていると聞きました...
アレックスA.

@AlexA。私たちはただ休憩を取っている、私はその間に何か他のものを試すことができます
...-

0

C ++-387バイト

ここでの最初の試みは、特にどのクラスが使用されているかを判断する際に、より多くのゴ​​ルフが必要です。

ゴルフ:

#include<cstdlib>
#include<cstdio>
#include<time.h>
int main(int c,char**v){char*o=*v,l=*v[1];int b=-1,s=-1,i=6,x=0,q=l>=67&&l<=68||l==77?4:l==70?0:l==87?3:l==82?1:5;srand(time(0));for(;i-->0;){int w=9,d=4,u=3,t;for(;d-->0;){t=rand()%6;if(t<w){u+=w<9?w:0;w=t;}else u+=t;}if(u>s){c=s;s=u;u=c;}if(s>b){c=s;s=b;b=c;}if(u>=0)o[x++]=u;}for(i=0;i<6;i++)printf("%d ",i==2?s:(i==q?b:o[--x]));}

むしろ無制限:

#include<cstdlib>
#include<cstdio>
#include<time.h>
int main(int c,char**v)
{
    //name of program must be at least 4 chars
    char*others=*v,clas=*v[1];
    int desired = clas>=67&&clas<=68||clas==77?4:clas==70?0:clas==87?3:clas==82?1:5; //TODO:

    srand(time(0));
    int best=-1,second=-1,i=6,otherIndex=0;
    for(;i-->0;)
    {
        int lowest=9,diecount=4,sum=3;
        for(;diecount-->0;)
        {
            int loc=rand()%6;
            if (loc<lowest)
            {
                sum+=lowest<9?lowest:0;
                lowest=loc;
            }
            else
            {
                sum+=loc;
            }
        }
        if(sum>second)
        {
            c=second;second=sum;sum=c;
        }
        if(second>best)
        {
            c=second;second=best;best=c;
        }
        if(sum>=0)
        {
            others[otherIndex++]=sum;
        }
    }

    for(i=0;i<6;i++)
    {
        printf("%d ",i==2?second:(i==desired?best:others[--otherIndex]));
    }

    getchar();
}
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.