Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/load -rs chess\chess.mrc
- #/chess
- alias eval { var %ticks = $ticks | say [eval] $1- => $iif($($1-,2),$v1,$!null) $+([,$iif($calc($ticks - %ticks) > 1000,$duration($calc($v1 /1000)),$v1 $+ ms),]) }
- alias chess {
- if ($dialog(chess)) { dialog -c chess }
- dialog -ams chess chess 20 200 300 400
- unset %chess_*
- }
- dialog chess {
- title "mIRC Chess"
- size -1 -1 172 135
- option dbu
- tab "Play Self", 1, 5 3 162 122
- text "Max time allowed for move(secs):", 2, 15 58 85 8, tab 1
- edit "40", 3, 100 58 25 10, tab 1
- button "Start Game", 4, 65 93 37 12, tab 1 default
- tab "Play Machine", 5
- text "Max time allowed for move(secs):", 6, 15 58 85 8, tab 5
- edit "40", 7, 100 58 25 10, tab 5
- button "Start Game", 8, 65 93 37 12, tab 5 default
- tab "Host Server", 9
- box "Server Configuration", 10, 20 23 130 63, tab 9
- text "Port:", 12, 24 33 15 8, tab 9
- edit "", 13, 55 48 40 10, tab 9 pass
- text "Password:", 14, 24 48 28 8, tab 9
- edit "", 15, 55 33 40 10, tab 9
- button "My IP", 16, 100 33 42 12, tab 9
- button "Setup Router", 17, 100 48 42 12, tab 9
- check "Make Public", 18, 24 64 50 10, tab 9
- check "CTCP Play", 19, 24 74 38 10, tab 9
- button "Start Game", 20, 65 93 37 12, tab 9 default
- tab "Join Server", 21
- box "Internet/LAN", 22, 20 20 134 44, tab 21
- text "IP Address:", 23, 25 30 30 8, tab 21
- edit "", 24, 60 30 70 11, tab 21
- button "Connect", 25, 45 43 37 12, tab 21 default
- button "Info", 26, 90 43 37 12, tab 21
- box "CTCP/PRIVMSG", 27, 20 65 134 44, tab 21
- text "Irc Nick:", 28, 25 75 30 8, tab 21
- edit "", 29, 60 74 70 11, tab 21
- button "Connect", 30, 45 88 37 12, tab 21 default
- button "Info", 31, 90 88 37 12, tab 21
- box "Current Game", 32, 4 0 167 126, hide
- text "Your Color:", 33, 15 20 70 8, hide group
- text "White Score:", 34, 15 30 70 8, hide group
- text "Black Score:", 35, 15 40 70 8, hide group
- box "Moves", 36, 88 18 75 40, hide
- list 37, 90 25 71 31, hide size
- text "Status:", 38, 15 72 21 8, hide group
- edit "", 39, 39 72 123 10, hide group read
- button "Leave Game", 40, 15 85 37 12, hide group
- button "Help", 41, 15 100 37 12, hide group
- box "Choose Color", 42, 113 87 50 34, hide
- button "White", 43, 120 97 37 8, hide
- button "Black", 44, 120 108 37 8, hide
- }
- on *:close:@chess:{
- .did -h chess 32,33,34,35,36,37,38,39,40,41,42,43,44
- .did -v chess 1
- unset %chess_*
- }
- on *:dialog:chess:close:0:{
- if ($window(@chess)) { window -c @chess }
- }
- on *:dialog:chess:sclick:4: {
- unset %chess_* | %chess_mode = self
- .signal chess_drawboard
- did -h chess 1
- did -v chess 32,33,34,35,36,37,38,39,40,41,42,43,44
- did -b chess 32,33,34,35,36,38,39,41
- did -r Chess 39
- }
- on *:dialog:chess:sclick:40: {
- window -c @chess
- did -h chess 32,33,34,35,36,37,38,39,40,41,42,43,44
- did -v chess 1
- unset %chess_*
- }
- on *:dialog:chess:sclick:43: {
- %chess_color = white
- .signal chess_fillboard
- did -h chess 42,43,44
- did -e chess 32,33,34,35,36,38,39,41
- }
- on *:dialog:chess:sclick:44: {
- %chess_color = black
- .signal chess_fillboard
- did -h chess 42,43,44
- did -e chess 32,33,34,35,36,38,39,41
- }
- on *:dialog:chess:sclick:19: {
- if ($did(chess,19).state == 1) {
- did -b chess 12,13,14,15,16,17,18
- }
- elseif ($did(chess,19).state == 0) {
- did -e chess 12,13,14,15,16,17,18
- }
- }
- on *:signal:chess_drawboard:{
- if (!$window(@chess)) {
- window -p @chess 0 0 427 452
- window -ph @chess.buf 0 0 427 452
- }
- drawpic @chess 0 0 chess/board.bmp
- }
- on *:signal:chess_fillboard:{
- if (!%chess_color) || (!%chess_mode) {
- echo 2 -s * error with Chess variables (line $calc($scriptline - 1) $+ , $qt($script) $+ )
- unset %chess_*
- window -c @chess
- if ($dialog(chess)) { dialog -c chess }
- dialog -ams chess chess 20 200 300 400
- halt
- }
- unset %chess_grid_*
- var %x_vector = $calc(8*50), %y_vector = $calc(8*50), %x = 20, %y = 20, %count = 0, %count1 = 0, %count2 = 0
- while (%y <= %x_vector) {
- var %x = 20, %count2 = 0
- inc %count1
- while (%x <= %y_vector) {
- inc %count | inc %count2
- var %draw = drawpic -t @chess 10040879 %x %y
- var %color1 = %chess_color, %color2 = $iif(%color1 == white,black,white)
- 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)
- if (%place == a8) { %draw chess/ $+ %color2 $+ _castle.bmp | %chess_grid_a8 = %color2 $+ _castle %x %y }
- elseif (%place == b8) { %draw chess/ $+ %color2 $+ _rook.bmp | %chess_grid_b8 = %color2 $+ _rook %x %y }
- elseif (%place == c8) { %draw chess/ $+ %color2 $+ _bishop.bmp | %chess_grid_c8 = %color2 $+ _bishop %x %y }
- elseif (%place == d8) { %draw chess/ $+ %color2 $+ _king.bmp | %chess_grid_d8 = %color2 $+ _king %x %y }
- elseif (%place == e8) { %draw chess/ $+ %color2 $+ _queen.bmp | %chess_grid_e8 = %color2 $+ _queen %x %y }
- elseif (%place == f8) { %draw chess/ $+ %color2 $+ _bishop.bmp | %chess_grid_f8 = %color2 $+ _bishop %x %y }
- elseif (%place == g8) { %draw chess/ $+ %color2 $+ _rook.bmp | %chess_grid_g8 = %color2 $+ _rook %x %y }
- elseif (%place == h8) { %draw chess/ $+ %color2 $+ _castle.bmp | %chess_grid_h8 = %color2 $+ _castle %x %y }
- elseif (%count isnum 9-16) { %draw chess/ $+ %color2 $+ _pawn.bmp | set %chess_grid_ $+ %place %color2 $+ _pawn %x %y }
- elseif (%count isnum 49-56) { %draw chess/ $+ %color1 $+ _pawn.bmp | set %chess_grid_ $+ %place %color1 $+ _pawn %x %y }
- elseif (%place == a1) { %draw chess/ $+ %color1 $+ _castle.bmp | %chess_grid_a1 = %color1 $+ _castle %x %y }
- elseif (%place == b1) { %draw chess/ $+ %color1 $+ _rook.bmp | %chess_grid_b1 = %color1 $+ _rook %x %y }
- elseif (%place == c1) { %draw chess/ $+ %color1 $+ _bishop.bmp | %chess_grid_c1 = %color1 $+ _bishop %x %y }
- elseif (%place == d1) { %draw chess/ $+ %color1 $+ _queen.bmp | %chess_grid_d1 = %color1 $+ _queen %x %y }
- elseif (%place == e1) { %draw chess/ $+ %color1 $+ _king.bmp | %chess_grid_e1 = %color1 $+ _king %x %y }
- elseif (%place == f1) { %draw chess/ $+ %color1 $+ _bishop.bmp | %chess_grid_f1 = %color1 $+ _bishop %x %y }
- elseif (%place == g1) { %draw chess/ $+ %color1 $+ _rook.bmp | %chess_grid_g1 = %color1 $+ _rook %x %y }
- elseif (%place == h1) { %draw chess/ $+ %color1 $+ _castle.bmp | %chess_grid_h1 = %color1 $+ _castle %x %y }
- else { set %chess_grid_ $+ %place 0 %x %y }
- inc %x 50
- }
- inc %y 50
- }
- }
- menu @chess {
- sclick {
- did -r Chess 39
- var %i1 = 0
- while (%i1 <= $var(%chess_grid_*,0)) {
- inc %i1
- 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)
- if ($mouse.x isnum %x1 $+ - $+ $calc(%x1 + 50)) && ($mouse.y isnum %y1 $+ - $+ $calc(%y1 + 50)) {
- if (%clicked1) {
- ;When person clicks box again unhighlight it, restore outline to black.
- set $(%var1,1) $remove(%value1,clicked)
- echo -a drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
- halt
- }
- else {
- var %i2 = 0
- while ($var(%chess_grid_*,%i2)) {
- inc %i2
- 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)
- if (%clicked2) {
- drawrect @chess 1 1 $calc(%x2 - 10) $calc(%y2 - 5) 50 50
- set $(%var2,1) $remove(%value2,clicked)
- }
- }
- ;When mouse clicks in box highlight that box, give it a red outline.
- drawrect @chess 4 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
- var %piece1 = $gettok(%value1,1,32), %place1 = $gettok(%var1,3,95)
- var %take_piece = $gettok(%chess_grid_ [ $+ [ %place1 ] ],1,32)
- set $(%var1,1) %value1 clicked
- if (%piece1 != 0) .timer 1 0 set % $+ chess_grid_selected %place1
- if (%chess_grid_selected) {
- var %place2 = $v1
- var %selected = %chess_grid_ [ $+ [ %chess_grid_selected ] ]
- var %piece2 = $gettok(%selected,1,32)
- if (%piece2 == 0) { unset %chess_grid_selected | halt }
- var %x3 = $gettok($gettok(%selected,2-,32),1,32), %y3 = $gettok($gettok(%selected,2-,32),2,32)
- var %pixel = $getdot(@chess,$calc(%x3 - 8),$calc(%y3 - 3)), %pixel2 = $getdot(@chess,$calc(%x1 - 8),$calc(%y1 - 3))
- var %take_piece = $gettok(%chess_grid_ [ $+ [ %place1 ] ],1,32)
- if (%take_piece) {
- var %piece_color = $gettok($gettok(%take_piece,1,32),1,95)
- if (%piece_color == %chess_color) {
- did -ra Chess 39 Invalid move.
- drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
- set %chess_grid_ $+ %place1 $remove(%chess_grid_ [ $+ [ %place1 ] ],clicked)
- .timer 5 0 unset %chess_grid_selected
- halt
- }
- else {
- did -ra Chess 39 %chess_color $gettok(%piece2,2,95) Takes %piece_color $gettok(%piece1,2,95) $+ .
- }
- .timer 5 0 unset %chess_grid_selected
- }
- else {
- if (%piece2 == white_pawn) {
- var %letter1 = $regml($regex(%place1,/([a-hA-H]+)/)), %letter2 = $regml($regex(%place2,/([a-hA-H]+)/))
- var %num1 = $regml($regex(%place1,/([1-8]+)/)), %num2 = $regml($regex(%place2,/([1-8]+)/))
- var %dif = $calc(%num1 - %num2)
- ;First Move
- if (*2 iswm %place2) {
- if (%dif <= 2) && (%letter1 == %letter2) { echo -a difference: %dif }
- else {
- did -ra Chess 39 Invalid move.
- drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
- set %chess_grid_ $+ %place1 $remove(%chess_grid_ [ $+ [ %place1 ] ],clicked)
- .timer 5 0 unset %chess_grid_selected
- halt
- }
- }
- else {
- if (%dif isnum 0-1) && (%letter1 == %letter2) { echo -a difference: %dif }
- else {
- did -ra Chess 39 Invalid move.
- drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
- set %chess_grid_ $+ %place1 $remove(%chess_grid_ [ $+ [ %place1 ] ],clicked)
- .timer 5 0 unset %chess_grid_selected
- halt
- }
- }
- }
- }
- drawrect -fr @chess %pixel 1 $calc(%x3 - 9) $calc(%y3 - 4) 45 45
- drawrect -fr @chess %pixel2 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
- drawrect @chess 1 1 $calc(%x1 - 10) $calc(%y1 - 5) 50 50
- drawpic -t @chess 10040879 %x1 %y1 chess/ $+ %piece2 $+ .bmp
- set $(%var1,1) %piece2 %x1 %y1
- set %chess_grid_ $+ %chess_grid_selected 0 %x3 %y3
- unset %chess_grid_selected
- }
- }
- }
- }
- }
- }
- alias urlparse {
- if ($regex($1-,/^(?:([a-z.+-]+)://|())(?:([^@:]+)(?::(.*?)|())@|()())([a-z0-9.-]+)(?::(\d+)|())(/.*)?$/i)) {
- if ($prop == proto) return $iif($regml(1) != $null,$ifmatch,http)
- elseif ($prop == user) return $regml(2)
- elseif ($prop == pass) return $regml(3)
- elseif ($prop == host) return $regml(4)
- elseif ($prop == port) {
- return $iif($regml(5) != $null,$ifmatch,$urlport($regml(1)))
- }
- elseif ($prop == path) return $iif($regml(6) != $null,$ifmatch,/)
- else return $true
- }
- else return $iif(!$prop,$false)
- }
- alias urlport {
- return $iif($findtok(http ftp telnet nntp https gopher,$1,32),$gettok(80 21 23 119 443 70,$ifmatch,32),0)
- }
- alias urlencode {
- var %t = $1-, %r = "", %c
- while ($len(%t)) {
- %c = $asc($left(%t,1))
- %r = %r $+ $iif((%c <= 32) || (%c >= 127),% $+ $base($ifmatch,10,16,2),$chr(%c))
- %t = $right(%t,-1)
- }
- return %r
- }
- alias urldecode {
- var %t = $replace($1-,+,$chr(32),% $+ 20,$chr(32)), %r = ""
- while ($regex(%t,/%([0-9A-F]{2})/i)) {
- .echo -q $regsub(%t,/(.*?)%([0-9A-F]{2})/i,,%t)
- %r = %r $+ $regml(1) $+ $chr($base($regml(2),16,10)))
- }
- return %r $+ %t
- }
- alias urlpath {
- var %t = $iif($right($1-,1) == /,/), %r = "", %i = 0
- while (%i < $numtok($1-,47)) {
- inc %i
- if ($gettok($1-,%i,47) == .) %r = %r $+ $iif($right(%r,1) != /,/)
- elseif ($gettok($1-,%i,47) != ..) %r = $instok(%r,$ifmatch,0,47)
- else {
- if (!$numtok(%r,47)) return $null
- %r = $deltok(%r,-1,47) $+ /
- }
- }
- return $iif(%r != /,/) $+ %r $+ $iif((%r != $null) && ($right(%r,1) != /),%t)
- }
- alias chess_drawboard {
- /*
- clear @chess
- var %x = 1, %y = 1, %d = 400, %grid = 0 %d 0 0 0 0 %d 0 %d %d 0 %d
- while (%x <= 8) {
- if (%x == 1) drawline @chess 1 5 %grid
- drawline @chess 1 5 $calc(%x * 50) %d $calc(%x * 50) 0
- drawline @chess 1 5 0 $calc(%y * 50) %d $calc(%y * 50)
- inc %x | inc %y
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement