Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Last active August 26, 2022 17:26
Show Gist options
  • Save neuro-sys/f46dcf59f9effe795400cb68cdcc9d1c to your computer and use it in GitHub Desktop.
Save neuro-sys/f46dcf59f9effe795400cb68cdcc9d1c to your computer and use it in GitHub Desktop.
0
dup constant minmax:min cell +
dup constant minmax:max cell +
constant minmax
\ The first element of each ability should be ability-score
0 constant ability-score
0
dup constant str:ability-score minmax +
dup constant str:hit-probability cell +
dup constant str:damage-adj cell +
dup constant str:weight-allow cell +
dup constant str:open-doors minmax +
dup constant bend-bars cell +
constant str
\ first element of each table is the row size
create str-table str ,
( abilility-score | hit-probability | damage-adj | weight-allow | open-doors | bend-bars )
3 , 3 , -3 , -1 , -350 , 1 , 1 , 0 ,
4 , 5 , -2 , -1 , -250 , 1 , 1 , 0 ,
6 , 7 , -1 , 0 , -150 , 1 , 1 , 0 ,
8 , 9 , 0 , 0 , 0 , 1 , 2 , 1 ,
10 , 11 , 0 , 0 , 0 , 1 , 2 , 2 ,
12 , 13 , 0 , 0 , 100 , 1 , 2 , 4 ,
14 , 15 , 0 , 0 , 200 , 1 , 2 , 7 ,
16 , 16 , 0 , 1 , 350 , 1 , 3 , 10 ,
17 , 17 , 1 , 1 , 500 , 1 , 3 , 13 ,
18 , 18 , 1 , 2 , 750 , 1 , 3 , 16 ,
-1 ,
0
dup constant int:ability-score minmax +
dup constant int:additional-lang cell +
constant int
create int-table int ,
( ability-score | additional-lang )
3 , 3 , 0 ,
4 , 4 , 0 ,
5 , 5 , 0 ,
6 , 6 , 0 ,
7 , 7 , 0 ,
8 , 8 , 1 ,
9 , 9 , 1 ,
10 , 10 , 2 ,
11 , 11 , 3 ,
12 , 12 , 3 ,
13 , 13 , 3 ,
14 , 14 , 4 ,
15 , 15 , 4 ,
16 , 16 , 5 ,
17 , 17 , 6 ,
18 , 18 , 7 ,
-1 ,
\ TODO: add all the remaining tables in the same way
: between ( a b c -- t ) rot dup >r swap <= swap r> swap >= and ;
: get ( addr offset -- val ) + @ ;
variable table-siz
: ability ( table score -- addr )
>r dup @ table-siz ! cell + ( table ) ( R: score )
begin
dup ability-score minmax:min + get ( table min ) ( R: score )
over ability-score minmax:max + get ( table score min max ) ( R: score )
r@ -rot between 0= ( table t ) ( R: score )
while
table-siz @ + ( table1 )
dup @ -1 = if rdrop rdrop drop 0 exit then
repeat
rdrop
;
: ability ( column table score -- n ) ability + @ ;
: assert <> abort" Failed to pass the test" ;
: test
str:weight-allow str-table 18 ability 750 assert
str:weight-allow str-table 3 ability -350 assert
str:weight-allow str-table 99 ability 0 assert
str:open-doors minmax:min + str-table 17 ability 1 assert
str:open-doors minmax:max + str-table 17 ability 3 assert
int:additional-lang int-table 7 ability 0 assert
int:additional-lang int-table 8 ability 1 assert
int:additional-lang int-table 18 ability 7 assert
int:additional-lang int-table 99 ability 0 assert
;
test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment