Implementation of Lucifers Pastime
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

116 行
2.4KB

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