manish

MasterVar Multiplayer Game by manish

Oct 6th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 20.34 KB | None | 0 0
  1. ############################################################
  2. ##       MasterVar - A Math Game For Masterminds!   ##
  3. ##       Version: 1.3             ##
  4. ##       By: manish               ##
  5. ##       irc.lunarirc.net   #LunarIRC #LunarGames   User - manish
  6. COMMANDS-
  7.  !mastervar - Start a game of MasterVar Multiplayer
  8. !mastervar 1 - Start a game of MasterVar Solo
  9. !stopmaster - Stop the game
  10. !surrender - Give up the game.
  11. !eval <expression> : Answer by writing your chosen numbers separated by spaces or by providing the entire expression. ##
  12. ############################################################
  13. on *:TEXT:!mastervar*:#: {
  14.   if ( %master != 1 ) && (%ongoing == $null) && ($2 == 1) {
  15.     set %ongoing MasterVar
  16.     set %chan $chan
  17.     set %master 1
  18.     set %round 1
  19.     msg $chan 9 You have began a game of 4MasterVarSolo.5 Get ready.....
  20.     if (%highestscorerofmastervar != $null) { msg %chan 6Latest Winner: 4 %highestscorerofmastervar }
  21.     set %player $nick
  22.     set %score 0
  23.     timer 1 3 nround
  24.   }
  25.   elseif ( %master != 1 ) && (%ongoing == $null) {
  26.     set %ongoing MasterVar
  27.     set %chan $chan
  28.     set %master 2
  29.     set %round 1
  30.     msg $chan 5MasterVar1 has been started. A series of numbers, operations and targets is given in each round. You have to use the numbers with the given operations correctly to reach the target number.
  31.     timer 1 2 msg $chan First player to 12 Score 50 points1 wins.
  32.     timer 1 4 mround
  33.   }
  34.  
  35. }
  36.  
  37. on *:TEXT:!stopmaster*:#: {
  38.   msg $chan 3 MasterVar has been ended or stopped.
  39.   endgame
  40. }
  41.  
  42. on *:TEXT:!surrender*:#: {
  43.   if ( %master == 1) {
  44.     msg %chan 3 You have decided to surrender, so you end up the game getting %score coins.
  45.     coins %player %score
  46.     endgame
  47.   }
  48. }
  49.  
  50. alias -l bscore {
  51.   if ( $istok(%plr,$1,32) == $false) {
  52.     set %plr $addtok(%plr,$1,32)
  53.     set %pts $instok(%pts,$2,$calc( $numtok(%pts,32) + 1 ),32)
  54.   }
  55.   else {
  56.     var %rq = $findtok(%plr,$1,1,32)
  57.     var %ne = $calc( $gettok(%pts,%rq,32) + $2 )
  58.     set %pts $deltok(%pts,%rq,32)
  59.     set %pts $instok(%pts,%ne,%rq,32)
  60.   }
  61.   var %p = $sorttok(%pts,32,nr)
  62.   if ( $gettok(%p,1,32) >= 50 ) { set %finished 1 }
  63. }
  64.  
  65. alias -l finish {
  66.   timers off
  67.   var %x = 1
  68.   while ( %x <= $numtok(%plr,32) ) {
  69.     coins $gettok(%plr,%x,32) $gettok(%pts,%x,32)
  70.     inc %x
  71.   }
  72.   var %t = $gettok($sorttok(%pts,32,nr),1,32)
  73.   var %q = $gettok(%plr,$findtok(%pts,%t,1,32),32)
  74.   msg %chan 5 %q has scored %t points, and so he is the winner of the game getting %t coins! Well played!  
  75.   timer 1 3 endgame
  76. }
  77.  
  78. alias -l validatea {
  79.   var %curop = $gettok(%ops,%mround,46)
  80.   var %curtar = $gettok(%target,%mround,46)
  81.   var %newer = $replace($1-,$left(%curop,1),$chr(32),$mid(%curop,2,1),$chr(32),$right(%curop,1),$chr(32))
  82.   var %x = 1
  83.   var %secondcopy = %copy
  84.   while ( %x <= $numtok(%newer,32) ) {
  85.     if ( $gettok(%newer,%x,32) !isnum ) || (!$istok(%secondcopy,$gettok(%newer,%x,32),32)) { return Your expression is either invalid, or does not evaluate to %curtar $+ . }
  86.     else {
  87.       var %secondcopy = $remtok(%secondcopy,$gettok(%newer,%x,32),1,32)
  88.     }
  89.     inc %x
  90.   }
  91.   if ( 2 \\ %round ) {
  92.     var %exp = $gettok(%newer,1,32) $+ $left(%curop,1) $+ $gettok(%newer,2,32) $+ $right(%curop,1) $+ $gettok(%newer,3,32)
  93.     if ( $numtok(%newer,32) != 3 ) { return Invalid! Make sure you are using exactly 3 numbers. }
  94.   }
  95.   if ( 2 // %round ) {
  96.     var %exp = $gettok(%newer,1,32) $+ $left(%curop,1) $+ $gettok(%newer,2,32) $+ $mid(%curop,2,1) $+ $gettok(%newer,3,32) $+ $right(%curop,1) $+ $gettok(%newer,4,32)
  97.     if ( $numtok(%newer,32) != 4 ) { return Invalid! Make sure you are using exactly 4 numbers. }
  98.   }
  99.   if ( $calc(%exp) != %curtar ) {
  100.     return Your expression does not evaluate to required target.
  101.   }
  102.   return $true
  103. }
  104.  
  105.  
  106. on *:TEXT:*:#: {
  107.   if ( %master == 2 ) && ( %answers == 1 ) && ( $chan == %chan ) {
  108.     if ( $validatea($1-) == $true ) {
  109.       var %curop = $gettok(%ops,%mround,46)
  110.       set %newer $replace($1-,$left(%curop,1),$chr(32),$mid(%curop,2,1),$chr(32),$right(%curop,1),$chr(32))
  111.       if ( $sorttok(%newer,32,n) == $sorttok($gettok(%nos,%mround,46),32,n) )  {
  112.         timers off
  113.         unset %answers
  114.         var %x = 1
  115.         msg %chan 9 You have chosen the correct numbers:5 %newer , and hence, you get $calc( 5 * ( 2 - %round % 2 ) ) points.
  116.         bscore $nick $calc( 5 * ( 2 - %round % 2 ) )
  117.         timer 1 2 score
  118.         while ( %x <= $numtok(%newer,32) ) {
  119.           set %copy $remtok(%copy,$gettok(%newer,%x,32),1,32)
  120.           inc %x
  121.         }
  122.  
  123.         if ( %finished != 1 ) {
  124.           inc %mround
  125.           if ( %mround == 4 ) && ($numtok(%copy,32) == 0 ) {
  126.             inc %round
  127.             unset %answers
  128.             timer 1 4 msg %chan 11 Congratulations,5 this round has been successfully completed. Be ready for the next round...
  129.             timer 1 6 mround
  130.           }
  131.           else {
  132.             timer 1 4 msg %chan Your numbers remaining are:9 %copy
  133.             timer 1 4 msg %chan Your current operation is:1 $gettok(%ops,%mround,46)$chr(58) $+ $chr(58) $grt(%round) and your 3current target11 is $gettok(%target,%mround,46) .
  134.             timer 1 4 set %answers 1
  135.             timer 1 64 solution
  136.           }
  137.         }
  138.         else {
  139.           timer 1 4 finish
  140.         }
  141.       }
  142.       else {
  143.         notice $nick Well that's not the correct expression. Try again!
  144.       }
  145.     }
  146.     else {
  147.       if ($remove($1-,$chr(32),+,-,*,/) isnum ) {
  148.         notice $nick $validatea($1-)
  149.       }
  150.     }
  151.   }
  152. }
  153.  
  154.  
  155.  
  156.  
  157. on *:TEXT:!eval*:#: {
  158.   if ( %answers == 1) && ($nick == %player) && ($validate($2-) == $true) {
  159.     var %curop = $gettok(%ops,%mround,46)
  160.     var %newer = $replace($2-,$left(%curop,1),$chr(32),$mid(%curop,2,1),$chr(32),$right(%curop,1),$chr(32))
  161.     var %x = 1
  162.     while ( %x <= $numtok(%newer,32) ) {
  163.       set %copy $remtok(%copy,$gettok(%newer,%x,32),1,32)
  164.       inc %x
  165.     }
  166.     msg %chan 5 You have used the numbers %newer to create5 $gettok(%target,%mround,46) .
  167.     msg %chan 9Well done. You get $calc($ceil($calc(%round / 2) ) * 5) points. You now have $numtok(%copy,32) numbers remaining.
  168.     set %score $calc(%score + $ceil($calc(%round / 2))  * 5)
  169.     inc %mround
  170.     if ( %mround == 4 ) && ($numtok(%copy,32) == 0 ) {
  171.       timers off
  172.       inc %round
  173.       unset %answers
  174.       timer 1 2 msg %chan 11 Congratulations,5 you have successfully completed this round.
  175.       if ( %round == 3 ) || ( %round == 5 ) {
  176.         timer 1 3 msg %chan 9 You get a bonus of 5 points for your amazing performance!
  177.         set %score $calc( %score + 5)
  178.       }
  179.       if ( %round != 5 ) { timer 1 4 msg %chan 10 Get ready for the next round... }  
  180.       timer 1 5 nround
  181.     }
  182.     else {
  183.       timer 1 2 msg %chan 11 Your current operation is: $gettok(%ops,%mround,46) and your 3current target11 is $gettok(%target,%mround,46) .
  184.       timer 1 2 notice $nick Your numbers remaining are: %copy
  185.     }
  186.   }
  187.   elseif ( %answers == 1) && ($nick == %player) && ($validate($2-) != $true) {
  188.     notice %player $validate($2-)
  189.   }
  190. }
  191.  
  192. alias -l validate {
  193.   var %curop = $gettok(%ops,%mround,46)
  194.   var %curtar = $gettok(%target,%mround,46)
  195.   var %newer = $replace($1-,$left(%curop,1),$chr(32),$mid(%curop,2,1),$chr(32),$right(%curop,1),$chr(32))
  196.   var %x = 1
  197.   var %secondcopy = %copy
  198.   while ( %x <= $numtok(%newer,32) ) {
  199.     if ( $gettok(%newer,%x,32) !isnum ) || (!$istok(%secondcopy,$gettok(%newer,%x,32),32)) { return Your expression is either invalid, or does not evaluate to %curtar $+ . }
  200.     else {
  201.       var %secondcopy = $remtok(%secondcopy,$gettok(%newer,%x,32),1,32)
  202.     }
  203.     inc %x
  204.   }
  205.   if ( %round <= 2 ) {
  206.     var %exp = $gettok(%newer,1,32) $+ $left(%curop,1) $+ $gettok(%newer,2,32) $+ $right(%curop,1) $+ $gettok(%newer,3,32)
  207.     if ( $numtok(%newer,32) != 3 ) { return Invalid! Make sure you are using exactly 3 numbers. }
  208.   }
  209.   if ( %round > 2 ) && ( %round <= 4 ) {
  210.     var %exp = $gettok(%newer,1,32) $+ $left(%curop,1) $+ $gettok(%newer,2,32) $+ $mid(%curop,2,1) $+ $gettok(%newer,3,32) $+ $right(%curop,1) $+ $gettok(%newer,4,32)
  211.     if ( $numtok(%newer,32) != 4 ) { return Invalid! Make sure you are using exactly 4 numbers. }
  212.   }
  213.   if ( $calc(%exp) != %curtar ) {
  214.     return Your expression is either incorrectly written or does not evaluate to the required target.
  215.   }
  216.   return $true
  217. }
  218.  
  219. alias -l timegone {
  220.   msg %chan 4 Your time is up! You finish the game, getting %score coins.
  221.   coins %player %score
  222.   endgame
  223. }
  224.  
  225. alias -l coins {
  226.   if ($read(coins.txt,w,* $+ $1 $+ *)) {
  227.     set %n $readn $+
  228.     set %data $read(coins.txt,w,* $+ $1 $+ *)
  229.     set %current $gettok(%data,2,32)
  230.     set %new $calc(%current + $2)
  231.     set %data $replace(%data,%current,%new)
  232.     write -dl $+ %n coins.txt
  233.     write coins.txt %data
  234.   }
  235.   else {
  236.     write coins.txt $1 $2
  237.   }
  238. }
  239.  
  240.  
  241. alias -l endgame {
  242.   timers off
  243.   unset %mround %round %chan %ongoing %master %copy %vars %target %nos %ops %player %ohg %answers %score %plr %pts %newer %finished %store %n %data %current %new %ofu %tc
  244. }
  245.  
  246. alias -l showscore {
  247.   if (%round != 1) {
  248.     msg %chan 4Current score: 5 %score
  249.   }
  250. }
  251. alias -l nround {
  252.   timers off
  253.   showscore
  254.   if ( %round <= 2 ) {
  255.     generate3
  256.     set %mround 1
  257.     set %copy $sorttok($replace(%nos,.,$chr(32)),32,n)
  258.     msg %chan 11 The operations selected are:1 $chr(124) $gettok(%ops,1,46) $chr(124) $gettok(%ops,2,46) $chr(124) $gettok(%ops,3,46) $chr(124)
  259.     timer 1 3 msg %chan 5 The targets are: $gettok(%target,1,46) $gettok(%target,2,46) $gettok(%target,3,46)
  260.     timer 1 5 msg %chan 6 Your numbers are: %copy
  261.     timer 1 5 notice %player Type !eval followed by the numbers or the expression to answer.
  262.     timer 1 5 set %answers 1
  263.     timer 1 65 timegone
  264.   }
  265.   elseif ( %round <= 4 ) {
  266.     generate4
  267.     set %mround 1
  268.     set %copy $sorttok($replace(%nos,.,$chr(32)),32,n)
  269.     msg %chan 11 The operations selected are:1 $chr(124) $gettok(%ops,1,46) $chr(124) $gettok(%ops,2,46) $chr(124) $gettok(%ops,3,46) $chr(124)
  270.     timer 1 3 msg %chan 5 The targets are: $gettok(%target,1,46) $gettok(%target,2,46) $gettok(%target,3,46)
  271.     timer 1 5 msg %chan 6 Your numbers are: %copy
  272.     timer 1 5 notice %player Type !eval followed by the numbers or the expression to answer.
  273.     timer 1 5 set %answers 1
  274.     timer 1 95 timegone
  275.   }
  276.   elseif (%round == 5) {
  277.     timer 1 2 msg %chan 3Congratulations! You have won the game, scoring %score points. You have earned %score coins.
  278.     timer 1 2 coins %player %score
  279.     timer 1 2 set %highestscorerofmastervar %player
  280.     timer 1 3 endgame
  281.   }
  282. }
  283.  
  284. alias -l score {
  285.   var %lv = 1
  286.   unset %store
  287.   while ( %lv <= $numtok(%pts,32) ) {
  288.     set %store %store 4 $gettok(%plr,%lv,32) :9 $gettok(%pts,%lv,32)
  289.     inc %lv
  290.   }
  291.   msg %chan 3 Current Scores: %store
  292. }
  293.  
  294. alias -l solution {
  295.   timers off
  296.   var %snos = $gettok(%nos,%mround,46)
  297.   var %cops = $gettok(%ops,%mround,46)
  298.   if ( 2 // %round ) { var %expression = $gettok(%snos,1,32) $+ $left(%cops,1) $+ $gettok(%snos,2,32) $+ $mid(%cops,2,1) $+ $gettok(%snos,3,32) $+ $right(%cops,1) $+ $gettok(%snos,4,32) }
  299.   if ( 2 \\ %round ) { var %expression = $gettok(%snos,1,32) $+ $left(%cops,1) $+ $gettok(%snos,2,32) $+ $right(%cops,1) $+ $gettok(%snos,3,32) }
  300.   msg %chan 12 Oops, looks like nobody got that! The correct expression was: %expression $+ . Get ready to continue...
  301.   inc %mround
  302.   set %newer %snos
  303.   var %x = 1
  304.   while ( %x <= $numtok(%newer,32) ) {
  305.     set %copy $remtok(%copy,$gettok(%newer,%x,32),1,32)
  306.     inc %x
  307.   }
  308.   if ( %mround == 4 ) && ($numtok(%copy,32) == 0 ) {
  309.     inc %round
  310.     unset %answers
  311.     timer 1 4 msg %chan 11 Proceeding to next round....
  312.     timer 1 6 mround
  313.   }
  314.   else {
  315.     timer 1 4 msg %chan Your numbers remaining are:9 %copy
  316.     timer 1 4 msg %chan Your current operation is: $gettok(%ops,%mround,46) $chr(58) $+ $chr(58) $grt(%round) and your 3current target11 is $gettok(%target,%mround,46) .
  317.     timer 1 4 set %answers 1
  318.     timer 1 64 solution
  319.   }
  320. }
  321.  
  322.  
  323.  
  324. alias -l mround {
  325.   timers off
  326.   if ( 2 // %round  ) {
  327.     generate4
  328.     set %mround 1
  329.     set %copy $sorttok($replace(%nos,.,$chr(32)),32,n)
  330.     msg %chan 11 The operations selected are:1 $chr(124) $gettok(%ops,1,46) $chr(124) $gettok(%ops,2,46) $chr(124) $gettok(%ops,3,46) $chr(124)
  331.     timer 1 4 msg %chan 5 The targets are: $gettok(%target,1,46) $gettok(%target,2,46) $gettok(%target,3,46)
  332.     timer 1 7 msg %chan 5 Your numbers are: %copy ,current target: $gettok(%target,1,46) 1(using $gettok(%ops,1,46) $chr(58) $+ $chr(58) %tc
  333.     timer 1 7 set %answers 1
  334.     timer 1 67 solution
  335.   }  
  336.   else {
  337.     generate3
  338.     set %mround 1
  339.     set %copy $sorttok($replace(%nos,.,$chr(32)),32,n)
  340.     msg %chan 11 The operations selected are:1 $chr(124) $gettok(%ops,1,46) $chr(124) $gettok(%ops,2,46) $chr(124) $gettok(%ops,3,46) $chr(124)
  341.     timer 1 4 msg %chan 5 The targets are: $gettok(%target,1,46) $gettok(%target,2,46) $gettok(%target,3,46)
  342.     timer 1 7 msg %chan 11 Your numbers are: %copy , and your current target is: $gettok(%target,1,46) (using $gettok(%ops,1,46) $chr(58) $+ $chr(58) %tc )
  343.     timer 1 7 set %answers 1
  344.     timer 1 67 solution
  345.   }
  346. }
  347.  
  348. alias -l getfactor {
  349.   unset %ohg
  350.   var %k = 2
  351.   while ( %k <= $calc($1 / 2 ) ) {
  352.     if ( %k // $1 ) {
  353.       set %ohg $addtok(%ohg,%k,46)
  354.     }
  355.     inc %k
  356.   }
  357.   return $gettok(%ohg,$rand(1,$numtok(%ohg,46)),46)
  358. }
  359.  
  360. alias -l grt {
  361.   set %ofu $gettok(%ops,%mround,46)
  362.   if ( $calc( $1 % 2 ) == 1 ) {
  363.     set %ofu n $+ $left(%ofu,1) $+ n $+ $right(%ofu,1) $+ n
  364.     set %tc $cleanequation(%ofu)
  365.   }
  366.   else {
  367.     set %ofu n $+ $left(%ofu,1) $+ n $+ $mid(%ofu,2,1) $+ n $+ $right(%ofu,1) $+ n
  368.     set %tc $cleanequation(%ofu)
  369.   }
  370.   return %tc
  371. }
  372.  
  373. alias -l generate3 {
  374.   set %vars ++.+-.+*.*+.+/./+.*/.**.*-.-*.-+.-+
  375.   var %x = 1
  376.   unset %target %nos %ops
  377.   var %list = 6.8.10.12.14.16.18.20/2/7.8.9.10.12.14.16.18.20/5.6.7.8.9.10/4.5.6.7.8.9.10.11.12/3.4.5.6.7.8.9/3.4.5.6.7.8.9.10.12.14.16.18.20/6.7.8.9.10.12.4.5
  378.   while (%x <= 3 ) {
  379.     var %m = $gettok(%vars,$rand($calc((%x - 1 )* 4 + 1),$calc(%x * 4)),46)
  380.     set %ops $instok(%ops,%m,%x,46)
  381.     var %thattok = $gettok(%list,$calc( 2 * $findtok(47.45.42.43,$asc($left(%m,1)),46) - 1 ),47)
  382.     var %thistok = $gettok(%list,$calc( 2 * $findtok(47.45.42.43,$asc($left(%m,1)),46)),47)
  383.     var %a = $gettok(%thattok,$rand(1,$numtok(%thattok,46)),46)
  384.     var %b = $gettok(%thistok,$rand(1,$numtok(%thistok,46)),46)
  385.     var %thistok = $gettok(%list,$calc( 2 * $findtok(47.45.42.43,$asc($right(%m,1)),46)),47)
  386.     var %c = $gettok(%thistok,$rand(1,$numtok(%thistok,46)),46)
  387.  
  388.     if ( $left(%m,1) == $chr(47) ) {
  389.       var %b = $getfactor(%a)
  390.     }
  391.     if ($right(%m,1) == $chr(47) ) {
  392.       var %b = $gettok($gettok(%list,1,47),$rand(1,8),46)
  393.       var %c = $getfactor(%b)
  394.     }
  395.     set %nos $instok(%nos,%a %b %c,%x,46)
  396.     var %exp = %a $+ $left(%m,1) $+ %b $+ $right(%m,1) $+ %c
  397.     set %target $instok(%target,$calc(%exp),%x,46)
  398.     inc %x
  399.   }
  400.  
  401.   set %ofu $gettok(%ops,1,46)
  402.   set %ofu n $+ $left(%ofu,1) $+ n $+ $right(%ofu,1) $+ n
  403.   set %tc $cleanequation(%ofu)
  404. }
  405.  
  406. alias -l generate4 {
  407.   set %vars +++.*+*.*+-.*-*.*++.*--.+-*.-+*.*+/./+*./*+./++.*-+.**/.*-/.*/-.+*+.*/+
  408.   var %x = 1
  409.   unset %target %nos %ops
  410.   var %list = 6.8.10.12.14.16.18.20/2/7.8.9.10.12.14.16.18.20/5.6.7.8.9.10/4.5.6.7.8.9.10.11.12/3.4.5.6.7.8.9/3.4.5.6.7.8.9.10.12.14.16.18.20/6.7.8.9.10.12.4.5
  411.   while (%x <= 3 ) {
  412.     var %m = $gettok(%vars,$rand($calc((%x - 1 )* 6 + 1),$calc(%x * 6)),46)
  413.     set %ops $instok(%ops,%m,%x,46)
  414.     var %thattok = $gettok(%list,$calc( 2 * $findtok(47.45.42.43,$asc($left(%m,1)),46) - 1 ),47)
  415.     var %thistok = $gettok(%list,$calc( 2 * $findtok(47.45.42.43,$asc($left(%m,1)),46)),47)
  416.     var %a = $gettok(%thattok,$rand(1,$numtok(%thattok,46)),46)
  417.     var %b = $gettok(%thistok,$rand(1,$numtok(%thistok,46)),46)
  418.     var %thistok = $gettok(%list,$calc( 2 * $findtok(47.45.42.43,$asc($mid(%m,2,1)),46)),47)
  419.     var %c = $gettok(%thistok,$rand(1,$numtok(%thistok,46)),46)
  420.     var %thistok = $gettok(%list,$calc( 2 * $findtok(47.45.42.43,$asc($right(%m,1)),46)),47)
  421.     var %d = $gettok(%thistok,$rand(1,$numtok(%thistok,46)),46)
  422.  
  423.     if ( $left(%m,1) == $chr(47) ) {
  424.       var %b = $getfactor(%a)
  425.     }
  426.     if ($mid(%m,2,1) == $chr(47) ) {
  427.       var %b = $gettok($gettok(%list,1,47),$rand(1,8),46)
  428.       var %c = $getfactor(%b)
  429.     }
  430.     if ($right(%m,1) == $chr(47) ) {
  431.       var %c = $gettok($gettok(%list,1,47),$rand(1,8),46)
  432.       var %d = $getfactor(%c)
  433.     }
  434.     set %nos $instok(%nos,%a %b %c %d,%x,46)
  435.     var %exp = %a $+ $left(%m,1) $+ %b $+ $mid(%m,2,1) $+ %c $+ $right(%m,1) $+ %d
  436.     set %target $instok(%target,$calc(%exp),%x,46)
  437.     inc %x
  438.   }
  439.   set %ofu $gettok(%ops,1,46)
  440.   set %ofu n $+ $left(%ofu,1) $+ n $+ $mid(%ofu,2,1) $+ n $+ $right(%ofu,1) $+ n
  441.   set %tc $cleanequation(%ofu)
  442. }
  443.  
  444. alias -l cleanEquation {
  445.   var %f = $1-
  446.   if ($count(%f,$chr(40)) != $count(%f,$chr(41))) %f = $iif($v1 > $v2,%f) $str($iif($v1 < $v2,$chr(40),$chr(41)) $+ $chr(32),$abs($calc($v2 - $v1))) $iif($v1 < $v2,%f)
  447.   var %e = $chr(40) $cleanseEquation(%f) $chr(41), %x = 1, %p, %count = 0, %abc = 161, %signs = $+(^,*/,$chr(37),+-), %q, %abcd, %y, %m, %t
  448.   while ($numtok(%e,32) > 1) {
  449.     %p = $gettok(%e,%x,32)
  450.     if (%p == $chr(40)) {
  451.       inc %count
  452.       var %count [ $+ [ $+(_,%count) ] ] %x
  453.     }
  454.     elseif (%p == $chr(41)) {
  455.       var %abc [ $+ [ $+(_,%abc) ] ] $gettok(%e,$+($($+($chr(37),count,_,%count),2),-,%x),32)
  456.       %e = $iif($+($($+($chr(37),count,_,%count),2)) > 1, $gettok(%e,$+(1,-,$calc($($+($chr(37),count,_,%count),2) - 1)),32),$null) $chr(%abc) $gettok(%e,$+($calc(%x + 1),-),32)
  457.       %m = $remove(%e,$chr(32))
  458.       if ($calc($count(%m,$chr(40))) > 1) && ($calc(($len(%m) - $count(%m,$chr(40))) * 2) <= 1) {
  459.         %t = $calc($pos(%e,$chr(40),$pos(%e,$chr(40),0)) + 1)
  460.         %e = $chr(40) $mid(%e,%t,$calc(($pos(%e,$chr(41),1) - 1) - %t)) $chr(41)
  461.       }
  462.       inc %abc
  463.       %x = 0
  464.       %count = 0
  465.     }
  466.     inc %x
  467.   }
  468.   while (%abc > 161) {
  469.     dec %abc
  470.     %p = $replace($($+($chr(37),abc,_,%abc),2),$str($chr(40),2),$chr(40),$str($chr(41),2),$chr(41))
  471.     if ($numtok(%p,32) == 3) && ($gettok(%p,2,32) !isnum) %p = $gettok(%p,2,32)
  472.     %abcd = 261
  473.     if ($numtok(%p,32) > 5) {
  474.       %y = 1
  475.       while (%y <= 5) {
  476.         %x = 1
  477.         while (%x <= $numtok(%p,32)) {
  478.           %q = $gettok(%p,%x,32)
  479.           if (%q isin $mid(%signs,%y,$iif(%y == 1,1,$iif(%y == 2,3,2)))) {
  480.             var %abcd [ $+ [ $+(_,%abcd) ] ] $+($chr(40),$chr(32),$gettok(%p,$+($calc(%x - 1),-,$calc(%x + 1)),32),$chr(32),$chr(41))
  481.             %p = $gettok(%p,$+(1,-,$calc(%x - 2)),32) $chr(%abcd) $gettok(%p,$+($calc(%x + 2),-),32)
  482.             inc %abcd
  483.           }
  484.           else inc %x
  485.         }
  486.         inc %y $iif(%y == 1,1,3)
  487.       }
  488.       while (%abcd > 261) {
  489.         dec %abcd
  490.         if ($numtok(%p,32) == 3) && ($gettok(%p,2,32) !isnum) %p = $($+($chr(37),abcd,_,%abcd),2)
  491.         else %p = $replacecs(%p,$chr(%abcd),$($+($chr(37),abcd,_,%abcd),2))
  492.       }
  493.     }
  494.     %e = $replacecs(%e,$chr(%abc),%p)
  495.   }
  496.   %e = $iif($regsubex(regextest,%e,\(([^()]|(?R))*\),$null),$+($chr(40),%e,$chr(41)),%e)
  497.   return $replace(%e,$+($chr(40),$chr(32)),$chr(40),$+($chr(32),$chr(41)),$chr(41))
  498. }
  499. alias -l cleanseEquation {
  500.   var %t, %s = $replace($remove($chr(40) $1- $chr(41),$chr(32)),$chr(41),$scc($chr(41)),$chr(40),$scc($chr(40)))
  501.   while (%s != $replace(%s,**,*,^^,^,$str($chr(37),2),$chr(37),//,/,++++,++,----,--,-+-+,-+,+-+-,+-,++-+,-+,--+-,+-,-++-,+-,+--+,-+,+---,+-,-+++,-+,++--,--,--++,++,+++-,+-,---+,-+)) %s = $v2
  502.   %s = $replace(%s,+-+,+,+--,+-,+++,+,++-,+-,-++,+,-+-,+-,--+,+,---,+-,-+,-,^--,^,*--,*,$+($chr(37),--),$chr(37),/--,/,^+-,^-,*+-,*-,$+($chr(37),+-),$+($chr(37),-),/+-,/-)
  503.   %s = $replace(%s,$scb(--),$scb($null),$scb(+-),$scb(-),$scb(++),$scb($null),$scb(-+),$scb(-),++,+,-+,-,*-,* $chr(512),+-,+ $chr(512),--,- $chr(512),/-,/ $chr(512),^-,^ $chr(512),$+($chr(37),-),$chr(37) $chr(512),$+($chr(40),$chr(160),-),$chr(512),$+($chr(40),$chr(160),+),$null,-,$scc(-),*+,*,^+,^,$+($chr(37),+),$chr(37),/+,/)
  504.   return $replace(%s,+,$scc(+),^,$scc(^),%,$scc(%),*,$scc(*),/,$scc(/),$chr(512),-,$chr(513),+,$chr(160),$chr(32))
  505. }
  506. alias -l scc return $+($chr(160),$1,$chr(160))
  507. alias -l scb return $+($chr(40),$chr(160),$1)
Add Comment
Please, Sign In to add comment