USING: qw sequences kernel math splitting io math.parser ;
IN: supereffective
: ptype>num ( str -- n ) qw{ normal fire water electric grass
ice fighting poison ground flying psychic bug rock ghost
dragon dark steel fairy } index ;
: type-chart ( -- seq ) {
{ 1 1 1 1 1 1 1 1 1 1 1 1 1/2 0 1 1 1/2 0 }
{ 1 1/2 1/2 1 2 2 1 1 1 1 1 2 1/2 1 1/2 1 2 1 }
{ 1 2 1/2 1 1/2 1 1 1 2 1 1 1 2 1 1/2 1 1 1 }
{ 1 1 2 1/2 1/2 1 1 1 0 2 1 1 1 1 1/2 1 1 1 }
{ 1 1/2 2 1 1/2 1 1 1/2 2 1/2 1 1/2 2 1 1/2 1 1/2 1 }
{ 1 1/2 1/2 1 2 1/2 1 1 2 2 1 1 1 1 2 1 1/2 1 }
{ 2 1 1 1 1 2 1 1/2 1 1/2 1/2 1/2 2 0 1 2 2 1/2 }
{ 1 1 1 1 2 1 1 1/2 1/2 1 1 1 1/2 1/2 1 1 0 2 }
{ 1 2 1 2 1/2 1 1 2 1 0 1 1/2 2 1 1 1 2 1 }
{ 1 1 1 1/2 2 1 2 1 1 1 1 2 1/2 1 1 1 1/2 1 }
{ 1 1 1 1 1 1 2 2 1 1 1/2 1 1 1 1 0 1/2 1 }
{ 1 1/2 1 1 2 1 1/2 1/2 1 1/2 2 1 1 1/2 1 2 1/2 1/2 }
{ 1 2 1 1 1 2 1/2 1 1/2 2 1 2 1 1 1 1 1/2 1 }
{ 0 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1/2 1 1 }
{ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1/2 0 }
{ 1 1/2 1/2 1/2 1 2 1 1 1 1 1 1 2 1 1 1 1/2 2 }
{ 1 1/2 1 1 1 1 2 1/2 1 1 1 1 1 1 2 2 1/2 1 } } ;
: type-row ( str -- seq ) ptype>num type-chart nth ;
: get-modifier ( atk def -- x ) swap type-row
[ ptype>num ] dip nth ;
: (final-modifier) ( seq -- atkseq defseq ) [ first ] keep 0
swap remove-nth [ length ] keep -rot swap [ ] curry
replicate swap ;
: final-modifier ( seq -- x ) (final-modifier)
[ get-modifier ] 2map 1 [ * ] reduce ;
: normalize ( str -- seq ) " ->" split harvest ;
lines [ normalize final-modifier number>string "x" append
write nl ] each