Implementation of Lucifers Pastime
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

121 řádky
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. 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 ft($$$){
  34. my ($b, $s0, $apl) = (shift, shift, shift);
  35. die "invalid ft() syntax $s0" unless $s0 =~ /^([A-Za-z]{2,3}[0-9]{1,2}\*(, )?){1,}$/;
  36. $b->ft_summon($s0, $apl);
  37. }
  38. sub draw($$$){
  39. my ($b, $s0, $apl) = (shift, shift, shift);
  40. die "invalid draw() syntax $s0" unless $s0 =~ /^([A-Za-z]{1,2} ){4}[A-Za-z]{1,2}$/;
  41. $b->draw($s0, $apl);
  42. }
  43. sub mt2($$$$){
  44. my ($b, $s0, $tc, $apl) = (shift, shift, shift, shift);
  45. # return $MOVE if $s0 =~ /([A-Za-z]{1,2}[0-9]{1,2}){2}/;
  46. # return $CAPTURE if $s0 =~ /\~/;
  47. # return $SACRIFICE if $s0 =~ /([A-Za-z]{1,2}[0-9]{1,2}' ?){2}/;
  48. # return $DRAW if $tc <= 1;
  49. ft($b, $s0, $apl) if is_ft($tc);
  50. draw($b, $s0, $apl) if is_draw($tc);
  51. }
  52. sub mt1($$$){
  53. my ($s0, $tc, $apl) = (shift, shift, shift);
  54. return is_summon($s0) ||
  55. is_move($s0) ||
  56. is_capture($s0) ||
  57. is_sacrifice($s0) ||
  58. is_draw($tc);
  59. }
  60. sub f2($$$){
  61. my ($s0, $tc, $apl) = (shift, shift, shift);
  62. # All the special cirucmstances
  63. # where a player moves twice are handled by spell cards
  64. # so this logic will do for now
  65. return LPST->P2 if $apl eq LPST->P1;
  66. return LPST->P1;
  67. }
  68. sub f1($$){
  69. my ($b, $ns0) = (shift, shift);
  70. my $apl;
  71. my $tc;
  72. $apl = LPST->P1;
  73. $tc = 0;
  74. for my $s0 (split(/\n/, $ns0)){
  75. mt2($b, $s0, $tc, $apl);
  76. $apl = f2($s0, $tc, $apl);
  77. # printf(">>%s\n", $s0);
  78. $tc++;
  79. }
  80. }
  81. my $ns0;
  82. $ns0 = "";
  83. $ns0 .= "A I Im Au H\n";
  84. $ns0 .= "A S Im Rc It\n";
  85. $ns0 .= "Aa1*, Ab1*, Ac1*, Ad1*, Ae1*, Qf1*, Ag1*, Ah1*, Ai1*, Aj1*, Ak1*, Ad2*, Ai2*, Aj2*, Ak2*, Ad3*\n";
  86. $ns0 .= "Aa11*, Ab11*, Ac11*, Ad11*, Ae11*, Qf11*\n";
  87. my $b;
  88. $b = LPST->new();
  89. f1($b, $ns0);
  90. $b->shade_all_p2_mvmt();
  91. $b->disp_board();