Implementation of Lucifers Pastime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.4KB

  1. #!/usr/bin/perl
  2. package NTVL;
  3. use warnings;
  4. use strict;
  5. use lib './';
  6. use LPST;
  7. # Move types
  8. my $SUMMON = 0b00000001;
  9. my $MOVE = 0b00000010;
  10. my $CAPTURE = 0b00000100;
  11. my $SACRIFICE = 0b00001000;
  12. # my $SPELL = 0b10000000;
  13. my $DRAW = 0b00010000;
  14. my $FT = 0b00100001;
  15. sub is_summon($){
  16. return $_[0] =~ /\*/ ? $SUMMON : 0;
  17. }
  18. sub is_move($){
  19. return $_[0] =~ /([A-Za-z]{1,2}[0-9]{1,2}){2}/ ? $MOVE : 0;
  20. }
  21. sub is_capture($){
  22. return $_[0] =~ /\~/ ? $CAPTURE : 0;
  23. }
  24. sub is_sacrifice($){
  25. return $_[0] =~ /([A-Za-z]{1,2}[0-9]{1,2}' ?){2}/ ? $SACRIFICE : 0;
  26. }
  27. sub is_draw($){
  28. return $_[0] <= 1 ? $DRAW : 0;
  29. }
  30. sub is_ft($){
  31. return $_[0] <= 3 && $_[0] > 1? $FT : 0;
  32. }
  33. sub mov($$$){
  34. my ($b, $s0, $apl) = (shift, shift, shift);
  35. die "invalid mov() syntax $s0" unless $s0 =~ /^[A-Za-z]{1,2}([A-Za-z][0-9]{1,2}){2}$/;
  36. $b->mov($s0, $apl);
  37. }
  38. sub ft($$$){
  39. my ($b, $s0, $apl) = (shift, shift, shift);
  40. die "invalid ft() syntax $s0" unless $s0 =~ /^([A-Za-z]{2,3}[0-9]{1,2}\*(, )?){1,}$/;
  41. $b->ft_summon($s0, $apl);
  42. }
  43. sub draw($$$){
  44. my ($b, $s0, $apl) = (shift, shift, shift);
  45. die "invalid draw() syntax $s0" unless $s0 =~ /^([A-Za-z]{1,2} ){4}[A-Za-z]{1,2}$/;
  46. $b->draw($s0, $apl);
  47. }
  48. sub mt2($$$$){
  49. my ($b, $s0, $tc, $apl) = (shift, shift, shift, shift);
  50. # return $MOVE if $s0 =~ /([A-Za-z]{1,2}[0-9]{1,2}){2}/;
  51. # return $CAPTURE if $s0 =~ /\~/;
  52. # return $SACRIFICE if $s0 =~ /([A-Za-z]{1,2}[0-9]{1,2}' ?){2}/;
  53. # return $DRAW if $tc <= 1;
  54. return mov($b, $s0, $apl) if is_move($s0);
  55. return ft($b, $s0, $apl) if is_ft($tc);
  56. return draw($b, $s0, $apl) if is_draw($tc);
  57. die "invalid syntax at \$tc: $tc - $s0";
  58. }
  59. sub mt1($$$){
  60. my ($s0, $tc, $apl) = (shift, shift, shift);
  61. return is_summon($s0) ||
  62. is_move($s0) ||
  63. is_capture($s0) ||
  64. is_sacrifice($s0) ||
  65. is_draw($tc);
  66. }
  67. sub f2($$$){
  68. my ($s0, $tc, $apl) = (shift, shift, shift);
  69. # All the special cirucmstances
  70. # where a player moves twice are handled by spell cards
  71. # so this logic will do for now
  72. return LPST->P2 if $apl eq LPST->P1;
  73. return LPST->P1;
  74. }
  75. sub f1($$$){
  76. my ($clas, $b, $ns0) = (shift, shift, shift);
  77. my $apl;
  78. my $tc;
  79. $apl = LPST->P1;
  80. $tc = 0;
  81. for my $s0 (split(/\n/, $ns0)){
  82. mt2($b, $s0, $tc, $apl);
  83. $apl = f2($s0, $tc, $apl);
  84. # printf(">>%s\n", $s0);
  85. $tc++;
  86. }
  87. }
  88. return 1;