Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cos 381 Day 9. © 2006 Pearson Addison-Wesley. All rights reserved. Agenda Assignment 2 Posted –Program a web-based Version of Soduku using JavaScript.

Similar presentations


Presentation on theme: "Cos 381 Day 9. © 2006 Pearson Addison-Wesley. All rights reserved. Agenda Assignment 2 Posted –Program a web-based Version of Soduku using JavaScript."— Presentation transcript:

1 Cos 381 Day 9

2 © 2006 Pearson Addison-Wesley. All rights reserved. Agenda Assignment 2 Posted –Program a web-based Version of Soduku using JavaScript and DOM –http://www.soduku.org/ to learn how to playhttp://www.soduku.org/ –Due Monday February 20 (one week) –You don't have enough JavaScript and DOM instruction to finish but you have enough to get started Soduku Help session –Key points »Graphic using images or Text using forms –Picking the ID for each element is crucial! »Suggestion use RC (row col) (00-88 or11-99) or GRC (grid row col) (111-933) (000-822)

3 © 2006 Pearson Addison-Wesley. All rights reserved. Soduku 00 11 000 01 12 001 03 14 100 06 17 08 19 10 21 022 122 30 41 33 44 36 47 60 71 63 74 66 77 88 99 + 1 +10 ((R-1)*10) + (C-1) R*10 + C

4 © 2006 Pearson Addison-Wesley. All rights reserved. To Store or Not to Store Only data structure available is a an array – game = new array (100) »Big to hold enough all the squares (81) »Requires some math to figure out where you are and if the solution is complete –Other approaches »Row = new array (9,9) »Col = new array (9,9) »Grids = new array (9,9) »Every play requires 3 updates »Checking for correct solutions is easy Sort each sub-array and see that each value = Index + 1 Another approach is not to bother storing that game but to read the game board –Graphic (name of graphic = number, etc 1.gif) –Textbox (read the value stored in the box using the Dom)

5 © 2006 Pearson Addison-Wesley. All rights reserved. Soduku Finding the top left corner of the 3*3 grid –Take the square you are in (RC) – RC/10 gives you the Row –RC%10 gives the Column – (Math.floor(Row/3)*3) gives you TL Corner Row –(Math.floor(Column/3)*3) gives you TL Corner Column »Example for square 56 Math.floor(5/3) = 1; 1*3 = 3 Math.floor(6/3) = 2; 2*3 = 6 Square 36 is the corner –(Math.floor((Row-1)/3)*3) +1 gives you TL Corner Row –(Math.floor((Column-1)/3)*3) +1 gives you TL Corner Column »Example for square 56 Math.floor(4/3) = 1; 1*3+1 = 4 Math.floor(5/3) = 1; 1*3 +1 = 4 Square 44 is the corner TL+1+2 +10+11+12 +20+21+22


Download ppt "Cos 381 Day 9. © 2006 Pearson Addison-Wesley. All rights reserved. Agenda Assignment 2 Posted –Program a web-based Version of Soduku using JavaScript."

Similar presentations


Ads by Google