Well I have never seen a sudoku script, so I decided to make one.
At first, I wondered how I could make my own thing that generates sudoku puzzles, but I gave up on that, and decided to use sockets.
I socketed to websudoku for those who want to know, and it was difficult for me to grab the information out of (if anyone decides to see what the socket gives back hehe)
Anyways, type /sudoku or right click > sudoku to start
You'll be presented to a window similar to:
Red numbers denote a given number (I'm going to try to make it so you can't edit this)
There are 4 levels of difficulty: Easy, Medium, Hard, Evil
In the bottom-right corner, there's the puzzle id, in case you want to see the puzzle-id on the website.
Now I have a very crude checker to see if you won or not, and if anyone would like to help me, and create a more efficient one, I'd be glad to look at it.
**Note: I have found a few people who helped test the script have issues with the background. Again, if anyone can help find the solution, I'd be glad to accept it. I also noticed people who use an addon and themes might find that it's a little weird.
To-Do:
-Better interface
-Better fix to preference stated by Kirby
Special thanks: vskyzv for helping with code and testing. kuru for testing
Hope you like it :)
Rate or hate.
Changelog
+: Added feature
-: Removed feature
X: Fixed glitch/bug
v0.1
Released Sudoku
v0.2
+: Can't change or delete given numbers
+: Added delete feature, Just hit Backspace on a cell
+: Added temporary fix, waits 10 seconds before clearing board when you win
X: Fixed bug where two numbers appear in the top-left box
;Sudoku 0.02
;Updated by Firstmate 01/14/09
;Place this script in remotes (alt-R or Tools > Script Editor)
;Right click in channel > Sudoku OR type /sudoku alternatively
;Click a box and fill in a number
;Click boxes to change difficulty
menu status,channel,query {
Sudoku:sudoku
}
alias sudoku {
window -pdoCk0 @Sudoku -1 -1 380 480
s.drawlines
drawrect -fr @Sudoku $rgb(0,0,0) 0 5 400 15 15
}
alias -l s.drawlines {
clear @Sudoku
drawfill -r @Sudoku $rgb(255,255,255) $rgb(255,255,255) 1 1
drawline -r @Sudoku $rgb(0,0,0) 2 5 5 365 5
drawline -r @Sudoku $rgb(0,0,0) 2 5 5 5 365
drawline -r @Sudoku $rgb(0,0,0) 2 5 365 365 365
drawline -r @Sudoku $rgb(0,0,0) 2 365 5 365 365
drawrect -r @Sudoku $rgb(0,0,0) 0 5 370 80 25
drawtext -r @Sudoku $rgb(0,0,0) Tahoma 14 15 372 Did I Win?
drawrect -r @Sudoku $rgb(0,0,0) 1 5 400 15 15
drawtext -r @Sudoku $rgb(0,0,0) Tahoma 14 25 400 Easy
drawrect -r @Sudoku $rgb(0,0,0) 1 65 400 15 15
drawtext -r @Sudoku $rgb(0,0,0) Tahoma 14 85 400 Medium
drawrect -r @Sudoku $rgb(0,0,0) 1 145 400 15 15
drawtext -r @Sudoku $rgb(0,0,0) Tahoma 14 165 400 Hard
drawrect -r @Sudoku $rgb(0,0,0) 1 205 400 15 15
drawtext -r @Sudoku $rgb(0,0,0) Tahoma 14 225 400 Evil
var %x 1
var %y 1
while (%x < 9) {
if ($calc(%x % 3) == 0) { drawline -r @Sudoku $rgb(0,0,0) 2 5 $calc((%x * 40) + 5) 365 $calc((%x * 40) + 5) }
else { drawline -r @Sudoku $rgb(0,0,0) 1 5 $calc((%x * 40) + 5) 365 $calc((%x * 40) + 5) }
inc %x
}
while (%y < 9) {
if ($calc(%y % 3) == 0) { drawline -r @Sudoku $rgb(0,0,0) 2 $calc((%y * 40) + 5) 5 $calc((%y * 40) + 5) 365 }
else { drawline -r @Sudoku $rgb(0,0,0) 1 $calc((%y * 40) + 5) 5 $calc((%y * 40) + 5) 365 }
inc %y
}
s.socket
}
menu @sudoku {
sclick: {
if ($inrect($mouse.x,$mouse.y,5,400,15,15)) {
s.drawlines
drawrect -fr @Sudoku $rgb(0,0,0) 0 5 400 15 15
.remove Sudoku.txt
set %s.level 1
}
if ($inrect($mouse.x,$mouse.y,65,400,15,15)) {
s.drawlines
drawrect -fr @Sudoku $rgb(0,0,0) 0 65 400 15 15
.remove Sudoku.txt
set %s.level 2
}
if ($inrect($mouse.x,$mouse.y,145,400,15,15)) {
s.drawlines
drawrect -fr @Sudoku $rgb(0,0,0) 0 145 400 15 15
.remove Sudoku.txt
set %s.level 3
}
if ($inrect($mouse.x,$mouse.y,205,400,15,15)) {
s.drawlines
drawrect -fr @Sudoku $rgb(0,0,0) 0 205 400 15 15
.remove Sudoku.txt
set %s.level 4
}
if ($inrect($mouse.x,$mouse.y,5, 370, 75, 30)) {
;did you win?
s.checkwin
}
if ($inrect($mouse.x,$mouse.y,5,5,365,365)) {
var %pos $s.checkpos($mouse.x,$mouse.y)
var %col $gettok(%pos,1,32)
var %row $gettok(%pos,2,32)
set %s.pos %pos
if (!%s.temp) { set %s.temp %pos | drawrect -f @Sudoku 0 0 $calc(((%col - 1) * 40) + 34) $calc(((%row - 1) * 40) + 6) 10 10 }
else {
var %cols $gettok(%s.temp,1,32)
var %rows $gettok(%s.temp,2,32)
drawrect -fr @Sudoku $rgb(255,255,255) 1 $calc(((%cols - 1) * 40) + 36) $calc(((%rows - 1) * 40) + 6) 8 8
set %s.temp %pos
drawrect -fr @Sudoku $rgb(0,0,0) 0 $calc(((%col - 1) * 40) + 36) $calc(((%row - 1) * 40) + 6) 8 8
}
;if they clicked in sudoku chart
}
}
}
on 1:KEYDOWN:@Sudoku:*: {
if ($keychar isnum && %s.pos && $keychar !== 0) {
var %col $gettok(%s.pos,1,32)
var %row $gettok(%s.pos,2,32)
if ($read(Sudoku.txt,s,$+(%col,$chr(44),%row))) {
write -ds $+ $+(%col,$chr(44),%row) Sudoku.txt
}
write sudoku.txt $+(%col,$chr(44),%row) $keychar
drawrect -fr @Sudoku $rgb(255,255,255) 1 $calc(((%col -1) * 40) + 6) $calc(((%row -1) * 40) + 6) 30 30
drawtext -r @Sudoku $rgb(0,0,0) Tahoma 24 $calc(((%col - 1) * 40) + 15) $calc(((%row - 1) * 40) + 10) $keychar
}
if ($keyval == 8 && %s.pos) {
var %col $gettok(%s.pos,1,32)
var %row $gettok(%s.pos,2,32)
write -ds $+ $+(%col,$chr(44),%row) Sudoku.txt
drawrect -fr @Sudoku $rgb(255,255,255) 1 $calc(((%col -1) * 40) + 6) $calc(((%row -1) * 40) + 6) 30 30
drawrect -fr @Sudoku $rgb(0,0,0) 0 $calc(((%col - 1) * 40) + 36) $calc(((%row - 1) * 40) + 6) 8 8
}
}
alias s.socket {
if ($sock(sudoku)) { sockclose sudoku }
sockopen sudoku view.websudoku.com 80
}
on *:sockopen:sudoku: {
sockwrite -nt $sockname GET /index.php?level= $+ %s.level HTTP/1.1
sockwrite -nt $sockname Host: websudoku.com
sockwrite -nt $sockname $crlf
}
on *:sockread:sudoku: {
var %s
sockread %s
if (Copy link for this puzzle isin %s) {
var %x = $remove($gettok($gettok($gettok($remove(%s,$chr(44),$chr(40),$chr(41)),2,62),2,32),4,61),$chr(34))
drawtext -r @Sudoku $rgb(0,0,0) Tahoma 10 290 430 ID: %x
}
.s.split %s
}
alias -l s.checkpos {
var %x $1
var %y $2
var %col,%row
var %i = 1, %j = 1
while (%i < 9) {
if (%x < $calc((%i * 40) + 5)) { %col = %i | break }
inc %i
}
while (%j < 9) {
if (%y < $calc((%j * 40) + 5)) { %row = %j | break }
inc %j
}
return %i %j
}
alias -l s.split {
var %t $remove($1-,$chr(40),$chr(44),$chr(41))
var %i = 1, %x = $gettok(%t,0,60), %p, %d, %y
while (%i < %x) {
%p = $gettok($gettok(%t,%i,62),1,60)
if ($left(%p,5) == INPUT && READONLY isin %p) {
;If they give a number
;Location of number cXY e.g. x45
%d = $remove($gettok($gettok($gettok($gettok(%t,$calc(%i -1),62),1,60),3,32),2,61),c)
;Value
%y = $noqt($gettok($gettok(%p,7,32),2,61))
var %col $left(%d,1)
var %row $right(%d,1)
write sudoku.txt $+($calc(%col + 1),$chr(44),$calc(%row + 1)) %y
drawtext -r @Sudoku $rgb(255,0,0) Tahoma 24 $calc((%col * 40) + 15) $calc((%row * 40) + 10) %y
}
inc %i
}
}
alias -l s.checkwin {
if ($lines(Sudoku.txt) !== 81) { drawrect -fr @Sudoku $rgb(255,255,255) 1 90 370 300 30 | drawtext -r @Sudoku $rgb(0,0,0) Tahoma 14 90 370 Fill in all the boxes! }
else {
var %x = 1, %p, %i
while (%x < 10) {
%p = %p $read(Sudoku.txt,s,$+(%x,$chr(44),1)) | %p = %p $read(Sudoku.txt,s,$+(%x,$chr(44),2)) | %p = %p $read(Sudoku.txt,s,$+(%x,$chr(44),3)) | %p = %p $read(Sudoku.txt,s,$+(%x,$chr(44),4)) | %p = %p $read(Sudoku.txt,s,$+(%x,$chr(44),5))
%p = %p $read(Sudoku.txt,s,$+(%x,$chr(44),6)) | %p = %p $read(Sudoku.txt,s,$+(%x,$chr(44),7)) | %p = %p $read(Sudoku.txt,s,$+(%x,$chr(44),8)) | %p = %p $read(Sudoku.txt,s,$+(%x,$chr(44),9))
echo -a %p
if ($istok(%p,1,32) && $istok(%p,2,32) && $istok(%p,3,32) && $istok(%p,4,32) && $istok(%p,5,32) && $istok(%p,6,32) && $istok(%p,7,32) && $istok(%p,8,32) && $istok(%p,9,32)) {
inc %i
}
%p = $null
inc %x
}
if (%i == 9) { drawrect -fr @Sudoku $rgb(255,255,255) 1 90 370 300 30 | drawtext -r @Sudoku $rgb(0,0,0) Tahoma 14 90 370 You Win! | s.drawlines }
else { drawrect -fr @Sudoku $rgb(255,255,255) 1 90 370 300 30 | drawtext -r @Sudoku $rgb(0,0,0) Tahoma 14 90 370 You lost :( Keep trying! }
}
}
on 1:CLOSE:@Sudoku: {
unset %s.*
.remove Sudoku.txt
}
here is the one i was talking about. http://www.mirc.net/projects.php?go=1125842856&get_desc=1
Nice job, I can't believe it's your first picwin :)
(Here's another Sudoku btw: http://www.mircscripts.org/comments.php?cid=2870)