SHARE
TWEET

Untitled

a guest Sep 22nd, 2017 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #/load -rs chess\chess.mrc
  2. #/chess
  3.  
  4. alias eval { var %ticks = $ticks | say [eval] $1- => $iif($($1-,2),$v1,$!null) $+([,$iif($calc($ticks - %ticks) > 1000,$duration($calc($v1 /1000)),$v1 $+ ms),])  }
  5.  
  6. alias chess {
  7.   if ($dialog(chess)) { dialog -c chess }
  8.   dialog -ams chess chess 20 200 300 400  
  9.   unset %chess_*
  10. }
  11. dialog chess {
  12.   title "mIRC Chess"
  13.   size -1 -1 172 135
  14.   option dbu
  15.   tab "Play Self", 1, 5 3 162 122
  16.   text "Max time allowed for move(secs):", 2, 15 58 85 8, tab 1
  17.   edit "40", 3, 100 58 25 10, tab 1
  18.   button "Start Game", 4, 65 93 37 12, tab 1 default
  19.   tab "Play Machine", 5
  20.   text "Max time allowed for move(secs):", 6, 15 58 85 8, tab 5
  21.   edit "40", 7, 100 58 25 10, tab 5
  22.   button "Start Game", 8, 65 93 37 12, tab 5 default
  23.   tab "Host Server", 9
  24.   box "Server Configuration", 10, 20 23 130 63, tab 9
  25.   text "Port:", 12, 24 33 15 8, tab 9
  26.   edit "", 13, 55 48 40 10, tab 9 pass
  27.   text "Password:", 14, 24 48 28 8, tab 9
  28.   edit "", 15, 55 33 40 10, tab 9
  29.   button "My IP", 16, 100 33 42 12, tab 9
  30.   button "Setup Router", 17, 100 48 42 12, tab 9
  31.   check "Make Public", 18, 24 64 50 10, tab 9
  32.   check "CTCP Play", 19, 24 74 38 10, tab 9
  33.   button "Start Game", 20, 65 93 37 12, tab 9 default
  34.   tab "Join Server", 21
  35.   box "Internet/LAN", 22, 20 20 134 44, tab 21
  36.   text "IP Address:", 23, 25 30 30 8, tab 21
  37.   edit "", 24, 60 30 70 11, tab 21
  38.   button "Connect", 25, 45 43 37 12, tab 21 default
  39.   button "Info", 26, 90 43 37 12, tab 21
  40.   box "CTCP/PRIVMSG", 27, 20 65 134 44, tab 21
  41.   text "Irc Nick:", 28, 25 75 30 8, tab 21
  42.   edit "", 29, 60 74 70 11, tab 21
  43.   button "Connect", 30, 45 88 37 12, tab 21 default
  44.   button "Info", 31, 90 88 37 12, tab 21
  45.   box "Current Game", 32, 4 0 167 126, hide
  46.   text "Your Color:", 33, 15 20 70 8, hide group
  47.   text "White Score:", 34, 15 30 70 8, hide group
  48.   text "Black Score:", 35, 15 40 70 8, hide group
  49.   box "Moves", 36, 88 18 75 40, hide
  50.   list 37, 90 25 71 31, hide size
  51.   text "Status:", 38, 15 72 21 8, hide group
  52.   edit "", 39, 39 72 123 10, hide group read
  53.   button "Leave Game", 40, 15 85 37 12, hide group
  54.   button "Help", 41, 15 100 37 12, hide group
  55.   box "Choose Color", 42, 113 87 50 34, hide
  56.   button "White", 43, 120 97 37 8, hide
  57.   button "Black", 44, 120 108 37 8, hide
  58. }
  59.  
  60. on *:close:@chess:{  
  61.   .did -h chess 32,33,34,35,36,37,38,39,40,41,42,43,44
  62.   .did -v chess 1
  63.   unset %chess_*
  64. }
  65. on *:dialog:chess:close:0:{  
  66.   if ($window(@chess)) { window -c @chess }  
  67. }
  68. on *:dialog:chess:sclick:4: {
  69.   unset %chess_* | %chess_mode = self
  70.   .signal chess_drawboard
  71.   did -h chess 1
  72.   did -v chess 32,33,34,35,36,37,38,39,40,41,42,43,44
  73.   did -b chess 32,33,34,35,36,38,39,41
  74.   did -r Chess 39
  75. }
  76. on *:dialog:chess:sclick:40: {
  77.   window -c @chess
  78.   did -h chess 32,33,34,35,36,37,38,39,40,41,42,43,44
  79.   did -v chess 1
  80.   unset %chess_*
  81. }
  82. on *:dialog:chess:sclick:43: {
  83.   %chess_color = white
  84.   .signal chess_fillboard
  85.   did -h chess 42,43,44
  86.   did -e chess 32,33,34,35,36,38,39,41
  87. }
  88. on *:dialog:chess:sclick:44: {
  89.   %chess_color = black
  90.   .signal chess_fillboard
  91.   did -h chess 42,43,44
  92.   did -e chess 32,33,34,35,36,38,39,41
  93. }
  94. on *:dialog:chess:sclick:19: {
  95.   if ($did(chess,19).state == 1) {  
  96.     did -b chess 12,13,14,15,16,17,18
  97.   }
  98.   elseif ($did(chess,19).state == 0) {  
  99.     did -e chess 12,13,14,15,16,17,18
  100.   }
  101. }
  102. on *:signal:chess_drawboard:{  
  103.   if (!$window(@chess)) {  
  104.     window -p @chess 0 0 427 452  
  105.     window -ph @chess.buf 0 0 427 452  
  106.   }
  107.   drawpic @chess 0 0 chess/board.bmp
  108. }
  109. on *:signal:chess_fillboard:{
  110.   if (!%chess_color) || (!%chess_mode) {  
  111.     echo 2 -s * error with Chess variables (line $calc($scriptline - 1) $+ , $qt($script) $+ )
  112.     unset %chess_*
  113.     window -c @chess
  114.     if ($dialog(chess)) { dialog -c chess }
  115.     dialog -ams chess chess 20 200 300 400  
  116.     halt
  117.   }
  118.  
  119.   unset %chess_grid_*
  120.  
  121.   var %x_vector = $calc(8*50), %y_vector = $calc(8*50), %x = 20, %y = 20, %count = 0, %count1 = 0, %count2 = 0
  122.   while (%y <= %x_vector) {
  123.     var %x = 20, %count2 = 0
  124.     inc %count1
  125.     while (%x <= %y_vector) {
  126.       inc %count | inc %count2  
  127.       var %draw = drawpic -t @chess 10040879 %x %y
  128.       var %color1 = %chess_color, %color2 = $iif(%color1 == white,black,white)
  129.       var %place = $replace(%count2,1,a,2,b,3,c,4,d,5,e,6,f,7,g,8,h) $+ $replacex(%count1,1,8,2,7,3,6,4,5,5,4,6,3,7,2,8,1)
  130.  
  131.       if (%place == a8) { %draw chess/ $+ %color2 $+ _castle.bmp | %chess_grid_a8 = %color2 $+ _castle %x %y }
  132.       elseif (%place == b8) { %draw chess/ $+ %color2 $+ _rook.bmp | %chess_grid_b8 = %color2 $+ _rook %x %y }
  133.       elseif (%place == c8) { %draw chess/ $+ %color2 $+ _bishop.bmp | %chess_grid_c8 = %color2 $+ _bishop %x %y }
  134.       elseif (%place == d8) { %draw chess/ $+ %color2 $+ _king.bmp | %chess_grid_d8 = %color2 $+ _king %x %y }
  135.       elseif (%place == e8) { %draw chess/ $+ %color2 $+ _queen.bmp | %chess_grid_e8 = %color2 $+ _queen %x %y }
  136.       elseif (%place == f8) { %draw chess/ $+ %color2 $+ _bishop.bmp | %chess_grid_f8 = %color2 $+ _bishop %x %y }
  137.       elseif (%place == g8) { %draw chess/ $+ %color2 $+ _rook.bmp | %chess_grid_g8 = %color2 $+ _rook %x %y }
  138.       elseif (%place == h8) { %draw chess/ $+ %color2 $+ _castle.bmp | %chess_grid_h8 = %color2 $+ _castle %x %y }
  139.       elseif (%count isnum 9-16) { %draw chess/ $+ %color2 $+ _pawn.bmp | set %chess_grid_ $+ %place %color2 $+ _pawn %x %y }
  140.  
  141.       elseif (%count isnum 49-56) { %draw chess/ $+ %color1 $+ _pawn.bmp | set %chess_grid_ $+ %place %color1 $+ _pawn %x %y }
  142.       elseif (%place == a1) { %draw chess/ $+ %color1 $+ _castle.bmp | %chess_grid_a1 = %color1 $+ _castle %x %y }
  143.       elseif (%place == b1) { %draw chess/ $+ %color1 $+ _rook.bmp | %chess_grid_b1 = %color1 $+ _rook %x %y }
  144.       elseif (%place == c1) { %draw chess/ $+ %color1 $+ _bishop.bmp | %chess_grid_c1 = %color1 $+ _bishop %x %y }
  145.       elseif (%place == d1) { %draw chess/ $+ %color1 $+ _queen.bmp | %chess_grid_d1 = %color1 $+ _queen %x %y }
  146.       elseif (%place == e1) { %draw chess/ $+ %color1 $+ _king.bmp | %chess_grid_e1 = %color1 $+ _king %x %y }
  147.       elseif (%place == f1) { %draw chess/ $+ %color1 $+ _bishop.bmp | %chess_grid_f1 = %color1 $+ _bishop %x %y }
  148.       elseif (%place == g1) { %draw chess/ $+ %color1 $+ _rook.bmp | %chess_grid_g1 = %color1 $+ _rook %x %y }
  149.       elseif (%place == h1) { %draw chess/ $+ %color1 $+ _castle.bmp | %chess_grid_h1 = %color1 $+ _castle %x %y }
  150.  
  151.       else { set %chess_grid_ $+ %place 0 %x %y }
  152.       inc %x 50
  153.     }
  154.     inc %y 50
  155.   }  
  156. }
  157. menu @chess {  
  158.   sclick {  
  159.     did -r Chess 39
  160.  
  161.     var %i1 = 0
  162.     while (%i1 <= $var(%chess_grid_*,0)) {  
  163.       inc %i1  
  164.       var %var1 = $var(%chess_grid_*,%i1), %value1 = $eval(%var1,2), %x1 = $gettok(%value1,2,32), %y1 = $gettok(%value1,3,32), %clicked1 = $gettok(%value1,4,32)
  165.       if ($mouse.x isnum %x1 $+ - $+ $calc(%x1 + 50)) && ($mouse.y isnum %y1 $+ - $+ $calc(%y1 + 50)) {  
  166.         if (%clicked1) {  
  167.           ;When person clicks box again unhighlight it, restore outline to black.
  168.           set $(%var1,1) $remove(%value1,clicked)
  169.           echo -a drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50  
  170.           halt
  171.         }
  172.         else {  
  173.           var %i2 = 0  
  174.           while ($var(%chess_grid_*,%i2)) {  
  175.             inc %i2
  176.             var %var2 = $var(%chess_grid_*,%i2), %value2 = $eval(%var2,2), %x2 = $gettok(%value2,2,32), %y2 = $gettok(%value2,3,32), %clicked2 = $gettok(%value2,4,32)
  177.             if (%clicked2) {  
  178.  
  179.               drawrect @chess 1 1 $calc(%x2 - 10) $calc(%y2 - 5) 50 50      
  180.               set $(%var2,1) $remove(%value2,clicked)
  181.             }
  182.           }
  183.  
  184.           ;When mouse clicks in box highlight that box, give it a red outline.
  185.           drawrect @chess 4 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
  186.           var %piece1 = $gettok(%value1,1,32), %place1 = $gettok(%var1,3,95)
  187.           var %take_piece = $gettok(%chess_grid_ [ $+ [ %place1 ] ],1,32)
  188.           set $(%var1,1) %value1 clicked  
  189.           if (%piece1 != 0) .timer 1 0 set % $+ chess_grid_selected %place1
  190.  
  191.           if (%chess_grid_selected) {  
  192.             var %place2 = $v1
  193.             var %selected = %chess_grid_ [ $+ [ %chess_grid_selected ] ]
  194.             var %piece2 = $gettok(%selected,1,32)
  195.             if (%piece2 == 0) { unset %chess_grid_selected | halt }
  196.             var %x3 = $gettok($gettok(%selected,2-,32),1,32), %y3 = $gettok($gettok(%selected,2-,32),2,32)
  197.             var %pixel = $getdot(@chess,$calc(%x3 - 8),$calc(%y3 - 3)), %pixel2 = $getdot(@chess,$calc(%x1 - 8),$calc(%y1 - 3))
  198.             var %take_piece = $gettok(%chess_grid_ [ $+ [ %place1 ] ],1,32)
  199.             if (%take_piece) {  
  200.               var %piece_color = $gettok($gettok(%take_piece,1,32),1,95)
  201.               if (%piece_color == %chess_color) {  
  202.                 did -ra Chess 39 Invalid move.
  203.                 drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
  204.                 set %chess_grid_ $+ %place1 $remove(%chess_grid_ [ $+ [ %place1 ] ],clicked)
  205.                 .timer 5 0 unset %chess_grid_selected
  206.                 halt
  207.               }
  208.               else {  
  209.                 did -ra Chess 39 %chess_color $gettok(%piece2,2,95) Takes %piece_color $gettok(%piece1,2,95) $+ .
  210.  
  211.               }
  212.               .timer 5 0 unset %chess_grid_selected  
  213.             }
  214.             else {  
  215.               if (%piece2 == white_pawn) {  
  216.                 var %letter1 = $regml($regex(%place1,/([a-hA-H]+)/)), %letter2 = $regml($regex(%place2,/([a-hA-H]+)/))
  217.                 var %num1 = $regml($regex(%place1,/([1-8]+)/)), %num2 = $regml($regex(%place2,/([1-8]+)/))
  218.                 var %dif = $calc(%num1 - %num2)
  219.                 ;First Move
  220.                 if (*2 iswm %place2) {
  221.                   if (%dif <= 2) && (%letter1 == %letter2) { echo -a difference: %dif }
  222.                   else {  
  223.                     did -ra Chess 39 Invalid move.
  224.                     drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
  225.                     set %chess_grid_ $+ %place1 $remove(%chess_grid_ [ $+ [ %place1 ] ],clicked)
  226.                     .timer 5 0 unset %chess_grid_selected
  227.                     halt
  228.                   }  
  229.                 }
  230.                 else {  
  231.                   if (%dif isnum 0-1) && (%letter1 == %letter2) { echo -a difference: %dif }
  232.                   else {  
  233.                     did -ra Chess 39 Invalid move.
  234.                     drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
  235.                     set %chess_grid_ $+ %place1 $remove(%chess_grid_ [ $+ [ %place1 ] ],clicked)
  236.                     .timer 5 0 unset %chess_grid_selected
  237.                     halt
  238.                   }  
  239.                 }
  240.  
  241.               }
  242.             }
  243.             drawrect -fr @chess %pixel 1 $calc(%x3 - 9) $calc(%y3 - 4) 45 45
  244.             drawrect -fr @chess %pixel2 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
  245.             drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
  246.             drawpic -t @chess 10040879 %x1 %y1 chess/ $+ %piece2 $+ .bmp
  247.             set $(%var1,1) %piece2 %x1 %y1
  248.             set %chess_grid_ $+ %chess_grid_selected 0 %x3 %y3
  249.             unset %chess_grid_selected
  250.           }
  251.         }
  252.       }  
  253.     }
  254.   }
  255. }
  256. alias urlparse {
  257.   if ($regex($1-,/^(?:([a-z.+-]+)://|())(?:([^@:]+)(?::(.*?)|())@|()())([a-z0-9.-]+)(?::(\d+)|())(/.*)?$/i)) {
  258.     if ($prop == proto) return $iif($regml(1) != $null,$ifmatch,http)
  259.     elseif ($prop == user) return $regml(2)
  260.     elseif ($prop == pass) return $regml(3)
  261.     elseif ($prop == host) return $regml(4)
  262.     elseif ($prop == port) {  
  263.       return $iif($regml(5) != $null,$ifmatch,$urlport($regml(1)))
  264.     }
  265.     elseif ($prop == path) return $iif($regml(6) != $null,$ifmatch,/)
  266.     else return $true
  267.   }
  268.   else return $iif(!$prop,$false)
  269. }
  270.  
  271. alias urlport {
  272.   return $iif($findtok(http ftp telnet nntp https gopher,$1,32),$gettok(80 21 23 119 443 70,$ifmatch,32),0)
  273. }
  274.  
  275. alias urlencode {
  276.   var %t = $1-, %r = "", %c
  277.   while ($len(%t)) {
  278.     %c = $asc($left(%t,1))
  279.     %r = %r $+ $iif((%c <= 32) || (%c >= 127),% $+ $base($ifmatch,10,16,2),$chr(%c))
  280.     %t = $right(%t,-1)
  281.   }
  282.   return %r
  283. }
  284.  
  285. alias urldecode {
  286.   var %t = $replace($1-,+,$chr(32),% $+ 20,$chr(32)), %r = ""
  287.   while ($regex(%t,/%([0-9A-F]{2})/i)) {
  288.     .echo -q $regsub(%t,/(.*?)%([0-9A-F]{2})/i,,%t)  
  289.     %r = %r $+ $regml(1) $+ $chr($base($regml(2),16,10)))
  290.   }
  291.   return %r $+ %t
  292. }
  293.  
  294. alias urlpath {
  295.   var %t = $iif($right($1-,1) == /,/), %r = "", %i = 0
  296.   while (%i < $numtok($1-,47)) {
  297.     inc %i
  298.     if ($gettok($1-,%i,47) == .) %r = %r $+ $iif($right(%r,1) != /,/)
  299.     elseif ($gettok($1-,%i,47) != ..) %r = $instok(%r,$ifmatch,0,47)
  300.     else {
  301.       if (!$numtok(%r,47)) return $null
  302.       %r = $deltok(%r,-1,47) $+ /
  303.     }
  304.   }
  305.   return $iif(%r != /,/) $+ %r $+ $iif((%r != $null) && ($right(%r,1) != /),%t)
  306. }
  307.  
  308. alias chess_drawboard {
  309.   /*
  310.   clear @chess
  311.   var %x = 1, %y = 1, %d = 400, %grid = 0 %d 0 0 0 0 %d 0 %d %d 0 %d
  312.   while (%x <= 8) {  
  313.     if (%x == 1) drawline @chess 1 5 %grid
  314.     drawline @chess 1 5 $calc(%x * 50) %d $calc(%x * 50) 0
  315.     drawline @chess 1 5 0 $calc(%y * 50) %d $calc(%y * 50)
  316.     inc %x | inc %y
  317.   }
  318.   */
  319. }
RAW Paste Data
Top