RPG attributes generator: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|J}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 36:
{{trans|Python}}
<
V total = 0
V count = 0
Line 50:
total = sum(attributes)
print(total‘ ’attributes)</
{{out}}
Line 59:
=={{header|8086 Assembly}}==
<
cpu 8086
putch: equ 2h
Line 147:
section .bss
rnddat: resb 4 ; RNG state
attrs: resb 6 ; Rolled attributes</
{{out}}
Line 162:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program rpg64.s */
Line 398:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
{{Output}}
<pre>
Line 413:
=={{header|Action!}}==
<
BYTE FUNC GenerateAttrib()
BYTE i,v,min,sum
Line 473:
FI
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/RPG_attributes_generator.png Screenshot from Atari 8-bit computer]
Line 485:
=={{header|ALGOL 68}}==
{{Trans|Action!}}
<
INT attrib count = 6;
Line 537:
OD
END</
{{out}}
<pre>
Line 549:
{{works with|Dyalog APL}}
<
{{out}}
Line 564:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
Line 888:
bx lr
</syntaxhighlight>
=={{header|Arturo}}==
<
while [or? 75 > sum vals
Line 906:
print ["values:" vals ]
print ["with sum:" sum vals]</
=={{header|Atari BASIC}}==
{{trans|Commodore BASIC}}
<
110 DIM AT(5)
120 DIM AT$(18)
Line 948:
450 IF K=78 THEN 140
460 POSITION 0,13
470 PRINT "Excellent. Good luck on your adventure!"</
{{Out}}
Line 971:
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<
if a < b then return a else return b
end function
Line 1,006:
print "-------"
print "TOT: "; sum
end</
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
Line 1,012:
=={{header|C}}==
{{trans|Go}}
<
#include <stdlib.h>
#include <time.h>
Line 1,053:
}
return 0;
}</
{{out}}
Line 1,066:
=={{header|C sharp|C#}}==
{{trans|Visual Basic .NET}}
<
using System.Collections.Generic;
using System.Linq;
Line 1,097:
} while (!good);
}
}</
{{out}}
sample outputs:
Line 1,106:
=={{header|C++}}==
GCC 4.9.2, unoptimised.
<
#include <ctime>
#include <iostream>
Line 1,157:
return 0;
}</
{{out}}
Sample run:
Line 1,166:
=={{header|Caché ObjectScript}}==
<syntaxhighlight lang="caché objectscript">RPGGEN
set attr = $lb("") ; empty list to start
write "Rules:",!,"1.) Total of 6 attributes must be at least 75.",!,"2.) At least two scores must be 15 or more.",!
Line 1,211:
} while (result '= 3)
quit</
{{out}}<pre>
Line 1,227:
=={{header|CLU}}==
<
% to use the random number generator.
%
Line 1,296:
stream$putright(po, int$unparse(stat), 4)
end
end start_up</
{{out}}
<pre>$ ./rpg_gen
Line 1,312:
Except for screen control codes, this is generic enough it could be used for many other 8-bit interpreted BASICs as well. (Applesoft, ZX Spectrum, etc.). Should work on all Commodore models. (Adjustment for screen width may be necessary on VIC-20.)
<
110 rem rosetta code - commodore basic
120 dim di(3):rem dice
Line 1,351:
470 if di(x)<di(x+1) then t=di(x):di(x)=di(x+1):di(x+1)=t
480 next x
490 return</
{{out}}
Line 1,395:
=={{header|Common Lisp}}==
<
(defpackage :rpg-generator
(:use :cl)
Line 1,414:
(format t ">= 15: ~A~%" (count-if (lambda (n) (>= n 15)) scores))
(return scores)))
</syntaxhighlight>
=={{header|Cowgol}}==
<
include "argv.coh";
Line 1,513:
print("\nTotal: ");
print_i8(total);
print_nl();</
{{out}}
Line 1,528:
=={{header|Crystal}}==
<
dices = Array(Int32).new(4) { rand(1..6) }
dices.sum - dices.min
Line 1,543:
stats = roll_character
puts "stats: #{stats}, sum is #{stats.sum}"
end</
sample output:
Line 1,561:
{{libheader| System.Generics.Collections}}
{{Trans|C#}}
<syntaxhighlight lang="delphi">
program RPG_Attributes_Generator;
Line 1,675:
end.
</syntaxhighlight>
{{out}}
Line 1,684:
=={{header|Dyalect}}==
{{trans|C#}}
<
var g3 = []
for i in 0..33 {
Line 1,727:
good = gs.Sum() >= 75 && hvc > 1
print(" - " + (good ? "success" : "failure"))
}</
{{out}}
Line 1,735:
=={{header|EasyLang}}==
<syntaxhighlight lang="text">len v[] 6
repeat
vsum = 0
Line 1,759:
.
print "Attributes: " & " " & v[]
print "Total: " & " " & vsum</
<pre>
Line 1,768:
=={{header|Factor}}==
{{Works with|Factor|0.98}}
<
math.statistics qw sequences ;
IN: rosetta-code.rpg-attributes-generator
Line 1,793:
[ "%s: %d\n" printf ] 2each nl stats-info ;
MAIN: main</
{{out}}
<pre>
Line 1,808:
=={{header|FreeBASIC}}==
<
function d6() as integer
Line 1,841:
next i
print "--------"
print using "TOT: ##";sum</
{{out}}<pre>STR: 14
CON: 11
Line 1,853:
=={{header|FOCAL}}==
<
01.20 F X=1,6;D 4;S AT(X)=S3;S T=T+S3
01.30 I (T-75)1.1
Line 1,876:
06.01 C--ROLL A D6
06.10 S A=FRAN()*10;S A=A-FITR(A)
06.20 S A=1+FITR(A*6)</
{{out}}
Line 1,902:
{{works with|GNU Forth}}
{{libheader|random.fs}}
<
: d6 ( -- roll ) 6 random 1 + ;
Line 1,937:
;
utime drop seed !</
{{Out}}
Line 1,944:
=={{header|Go}}==
<
import (
Line 1,989:
break
}
}</
{{out}}
Line 2,001:
=={{header|Haskell}}==
<
import System.Random (randomRIO)
import Data.Bool (bool)
Line 2,019:
-------------------------- TEST ---------------------------
main :: IO ()
main = replicateM 10 character >>= mapM_ (print . (sum >>= (,)))</
{{Out}}
<pre>Sample computation:
Line 2,036:
=={{header|J}}==
'twould be more efficient to work with index origin 0, then increment the roll once at output.
<syntaxhighlight lang="j">
roll=: 1 + 4 6 ?@:$ 6:
massage=: +/ - <./
Line 2,049:
NB. use: generate_character 'name'
generate_character=: (; (+/ ; ])@:([: generate_attributes@:show Until accept 0:))&>@:boxopen
</syntaxhighlight>
Line 2,082:
=={{header|Java}}==
<
import java.util.Random;
import java.util.stream.Stream;
Line 2,115:
}
}
}</
{{Out}}
<pre>
Line 2,124:
=={{header|Javascript}}==
===Imperative===
<
const stats = {
total: 0,
Line 2,157:
${rolledCharacter.rolls.join(', ')}
Their sum is ${rolledCharacter.total} and ${rolledCharacter.rolls.filter(a => a >= 15).length} of them are >= 15`);</
{{out}}
Line 2,170:
===Functional===
{{Trans|Python}} (Functional composition version)
<
'use strict';
Line 2,293:
// MAIN ---
return main();
})();</
{{Out}}
A sample of 10 character attribute sets:
Line 2,308:
=={{header|Julia}}==
<
function rollRPGtoon()
Line 2,329:
rollRPGtoon()
rollRPGtoon()
</
New RPG character roll: [15, 16, 15, 11, 9, 15]. Sum is 81, and 4 are >= 15.
New RPG character roll: [12, 14, 15, 12, 10, 16]. Sum is 79, and 2 are >= 15.
Line 2,336:
=={{header|Kotlin}}==
<
fun main() {
Line 2,351:
break
}
}</
{{output}}
Line 2,361:
=={{header|Ksh}}==
<
#!/bin/ksh
Line 2,432:
print "Attribute value total: ${total}"
print "Attribule count >= 15: ${cnt15}"
</syntaxhighlight>
{{out}}<pre>
strength: 11
Line 2,444:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
While[! valid,
try = Map[Total[TakeLargest[#, 3]] &,
Line 2,452:
]
]
{Total[try], try}</
{{out}}
<pre>{78, {13, 15, 9, 13, 12, 16}}</pre>
Line 2,458:
=={{header|min}}==
{{works with|min|0.19.6}}
<
; Implement some general operators we'll need that aren't in the library.
Line 2,474:
(big (dup special?) () (pop big) () linrec) :stats ; Roll a set of big and special attributes.
stats puts "Total: " print! sum puts!</
{{out}}
<pre>
Line 2,482:
=={{header|MiniScript}}==
<
results = []
for i in range(0,3)
Line 2,508:
end while
print "Success!"
</syntaxhighlight>
{{out}}
<pre>Attribute values: 11, 13, 8, 10, 8, 10
Line 2,527:
=={{header|Nim}}==
<syntaxhighlight lang="nim">
# Import "random" to get random numbers and "algorithm" to get sorting functions for arrays.
import random, algorithm
Line 2,561:
if not twoFifteens(sixAttr) or sumAttr < 75: echo "Not good enough. Rerolling..."
else: break
</syntaxhighlight>
Sample output: <pre>
Line 2,572:
=={{header|OCaml}}==
Original version by [http://rosettacode.org/wiki/User:Vanyamil User:Vanyamil]
<syntaxhighlight lang="ocaml">
(* Task : RPG_attributes_generator *)
Line 2,608:
let s = valid_set () in
List.iter (fun i -> print_int i; print_string ", ") s
</syntaxhighlight>
{{out}}
<pre>
Line 2,616:
=={{header|Pascal|FreePascal}}==
<syntaxhighlight lang="pascal">
program attributes;
Line 2,656:
writeln(' ---');
end.
</syntaxhighlight>
{{out}}
<pre>
Line 2,691:
=={{header|Perl}}==
<
use List::Util 'sum';
Line 2,710:
printf "%s = %2d\n", $attr_names[$_], $attr[$_] for 0..$#attr;
printf "Sum = %d, with %d attributes >= $hero_attr_min\n", sum(@attr), heroic(@attr);</
{{out}}
<pre>Str = 13
Line 2,721:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">numbers</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">)</span>
Line 2,740:
<span style="color: #000000;">numbers</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nTheir sum is %d and %d of them are >=15\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">})</span>
<!--</
{{out}}
<pre>
Line 2,753:
=={{header|PHP}}==
===Version 1===
<
$attributesTotal = 0;
Line 2,783:
}
print_r($attributes);</
===Version 2===
<
class CharacterGenerator {
Line 2,825:
print "Attribute Total: $attributesTotal\n";
print "Attributes: $attributesString";</
{{out}}
Line 2,832:
=={{header|Plain English}}==
<
Allocate memory for an entry.
Put the attribute into the entry's attribute.
Line 2,911:
If the entry's next is not nil, write ", " on the console without advancing.
Put the entry's next into the entry.
Repeat.</
{{out}}
<pre>
Line 2,920:
=={{header|PureBasic}}==
<
#heroicAttributeCountMinimum = 2
#attributeSumMinimum = 75
Line 2,976:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</
Sample output:
<pre>Attributes generated: [13, 17, 17, 11, 9, 17]
Line 2,983:
=={{header|Python}}==
===Python: Simple===
<
random.seed()
attributes_total = 0
Line 3,009:
attributes_total = sum(attributes)
print(attributes_total, attributes)</
{{out}}
Line 3,016:
===Python: Nested Comprehensions #1===
<
random.seed()
total = 0
Line 3,030:
total = sum(attributes)
print(total, attributes)</
{{out}}
Line 3,038:
===Python: Nested Comprehensions #2===
With comprehensions for checking candidate values in the while expression.
<
def compute():
Line 3,049:
for i in range(3):
print(*compute())
</syntaxhighlight>
{{out}}
Line 3,059:
Composing a hero-generator from reusable functions:
{{Works with|Python|3.7}}
<
from itertools import islice
Line 3,175:
if __name__ == '__main__':
main()</
<pre>A sample of 10:
Line 3,191:
===Python: One-liner===
Just because you can, doesn't mean you should.
<
import random; print((lambda attr: f"Attributes: {attr}\nTotal: {sum(attr)}")((lambda func, roll_func: func(func, roll_func, roll_func()))((lambda func, roll_func, rolls: rolls if sum(rolls) >= 75 and rolls.count(15) >= 2 else func(func, roll_func, roll_func())), lambda: [sum(sorted(random.randint(1, 6) for _ in range(4))[1:]) for _ in range(6)])))
</syntaxhighlight>
<pre>
Attributes: [16, 15, 15, 14, 8, 10]
Line 3,200:
=={{header|Quackery}}==
<
[ 0 ]'[ rot witheach
Line 3,224:
say 'Sum: ' dup sum echo cr
say '# of attributes > 14: '
count [ 14 > ] echo</
{{out}}
<pre>
Line 3,234:
=={{header|Racket}}==
<
(define (d6 . _)
Line 3,251:
(module+ main
(define-values (rolled-stats total) (generate-character))
(printf "Rolls:\t~a~%Total:\t~a" rolled-stats total))</
{{out}}
Line 3,259:
=={{header|R}}==
The base library already has an attributes function, so we avoid using that name. Otherwise, this is R's bread and butter.
<
{
stats <- c(STR = 0, DEX = 0, CON = 0, INT = 0, WIS = 0, CHA = 0)
Line 3,269:
if(sum(stats >= 15) < 2 || (stats["TOT"] <- sum(stats)) < 75) Recall() else stats
}
print(genStats())</
{{out}}
Line 3,278:
(formerly Perl 6)
{{works with|Rakudo Star|2018.04.1}}
<syntaxhighlight lang="raku"
my @attr-names = <Str Int Wis Dex Con Cha>;
Line 3,291:
say @attr-names Z=> @attr;
say "Sum: {@attr.sum}, with {heroic(@attr)} attributes >= $hero_attr_min";</
{{out}}
<pre>
Line 3,299:
=={{header|Red}}==
<
raw-attribute: does [
Line 3,349:
]
show-attributes attributes</
{{out}}
<pre>
Line 3,365:
=={{header|REXX}}==
===version 1===
<
Generates 4 random, whole values between 1 and 6.
Saves the sum of the 3 largest values.
Line 3,428:
swl=swl wa.i
End
Return strip(swl)</
{{out}}
<pre>I:\>rexx cast
Line 3,439:
===version 2===
This REXX version doesn't need a sort to compute the sum of the largest three (of four) values.
<
do until m>=2 & $$>=75; $$= 0; list= /*do rolls until requirements are met. */
m= 0 /*the number of values ≥ 15 (so far).*/
Line 3,452:
end /*do 6*/ /* [↑] gen six core attribute values. */
end /*until*/ /*stick a fork in it, we're all done. */
say 'The total for ' list " is ──► " $$', ' m " entries are ≥ 15."</
{{out|output|text= when using the default (internal) inputs:}}
<pre>
Line 3,460:
===version 3===
A variation of version 2
<
Do n=1 By 1 until m>=2 & tot>=75;
slist=''
Line 3,479:
Say 'the total for' space(slist) 'is -->' tot', 'm' entries are >= 15.'
end
Say 'Solution found with' n 'iterations'</
{{out}}
<pre>I:\>rexx rpg
Line 3,488:
=={{header|Ring}}==
<
# Project : RPG Attributes Generator
Line 3,533:
line = line + "])"
see line + nl
</syntaxhighlight>
Output:
<pre>
Line 3,540:
=={{header|Ruby}}==
<
until res.sum >= 75 && res.count{|n| n >= 15} >= 2 do
res = Array.new(6) do
Line 3,550:
p res
puts "sum: #{res.sum}"
</syntaxhighlight>
{{out}}
<pre>[12, 14, 17, 12, 16, 9]
Line 3,557:
=={{header|Run BASIC}}==
<
data "STR", "CON", "DEX", "INT", "WIS", "CHA"
for i = 1 to 6
Line 3,589:
a = d6() : b = d6() : c = d6() : d = d6()
rollstat = a + b + c + d - min(min(a, b), min(c, d))
end function</
=={{header|Rust}}==
Line 3,595:
{{libheader|rand}}
{{works with|Rust|2018}}
<
use rand::distributions::Uniform;
use rand::prelude::{thread_rng, ThreadRng};
Line 3,672:
}
}
</syntaxhighlight>
{{out}}
Sample output, running the generator ten times:
Line 3,690:
=={{header|Scala}}==
<
import scala.util.Random
Random.setSeed(1)
Line 3,711:
println("picked => " + getCharacter.mkString("[", ",", "]"))
</syntaxhighlight>
<pre>
Line 3,722:
=={{header|Seed7}}==
<
const proc: main is func
Line 3,759:
writeln(" ----");
writeln("Total " <& total lpad 3);
end func;</
{{out}}
Line 3,777:
{{trans|FreeBASIC}}
{{works with|QBasic}}
<
IF a < b THEN LET min = a ELSE LET min = b
END FUNCTION
Line 3,818:
PRINT "--------"
PRINT "TOT: "; sum
END</
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
Line 3,824:
=={{header|uBasic/4tH}}==
{{trans|Yabasic}}
<syntaxhighlight lang="text">dim @n(6)
@n(0) := "STR"
@n(1) := "CON"
Line 3,857:
local (4)
a@ = FUNC(_d6) : b@ = FUNC(_d6) : c@ = FUNC(_d6) : d@ = FUNC(_d6)
return (a@ + b@ + c@ + d@ - Min(Min(a@, b@), Min(c@, d@)))</
{{Out}}
<pre>STR: 17
Line 3,874:
{{works with|Zsh}}
<
typeset attrs=(str dex con int wis cha)
typeset -A values
Line 3,910:
main "$@"
</syntaxhighlight>
{{Out}}
<pre>str: 12
Line 3,921:
=={{header|Visual Basic .NET}}==
repeats until a successful outcome occurs
<
Dim r As New Random
Line 3,946:
Loop Until good
End Sub
End Module</
{{out}}
sample outputs:
Line 3,963:
=={{header|Wren}}==
{{libheader|Wren-sort}}
<
import "/sort" for Sort
Line 3,985:
}
}
}</
{{out}}
Line 3,995:
=={{header|XPL0}}==
<
int I, R, Min, SI, Sum, Die(4);
[Min:= 7; Sum:= 0;
Line 4,020:
[IntOut(0, Value(J)); ChOut(0, ^ )];
CrLf(0);
]</
{{out}}
Line 4,030:
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<
//simulates a marked regular hexahedron coming to rest on a plane
return 1 + int(ran(6))
Line 4,067:
next i
print "-------\nTOT: ", sum
end</
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
=={{header|zkl}}==
<
do{
attrs.clear();
Line 4,081:
}while((S=attrs.sum(0))<75 or (N=attrs.filter('>=(15)).len())<2);
println("Random numbers: %s\nSums to %d, with %d >= 15"
.fmt(attrs.concat(","),S,N));</
{{out}}
<pre>
|