<%@ page import="javax.servlet.http.*" %> <%@ include file="sudoku-data.jsp" %> <%! String sessionid; String puzzle=""; String puzzleid; String submitted; String duration; String soln = ""; String s=""; String HTMLtitle; String Level; String PreviousDate; String d2; String Replay; int puzzlenum; int j = 0; Cookie[] cookies; Cookie chocChip; String CookieName; int CookieValue; int lasteasy = 0; int lastmedium = 0; int lasthard = 0; int num; int num2; String IntToString(int i) { Integer ii = new Integer( i ); return ii.toString(); } int StringToInt(String s) { return (int)Integer.parseInt(s); } /** * gks get a random integer depending on the value of * L - which is the name of a cookie, I think. * gks changed this to have response in the call. * @param response Http Response * @param L a cookie name (may be null; if so, default to 'e') * @return (?What??) */ int GetRandom(HttpServletResponse response, String L) { // gks guard against no cookie if ( L == null ){ L = "e"; } if (L.equals("e")) {num = nume;num2 = lasteasy;} if (L.equals("m")) {num = numm;num2 = lastmedium;} if (L.equals("h")) {num = numh;num2 = lasthard;} if (num2 > -1) { if (num2 < num - 1) { ++num2; chocChip = new Cookie(L, IntToString(num2)); chocChip.setMaxAge(365 * 24 * 60 * 60); response.addCookie(chocChip); return num2; } else { chocChip = new Cookie(L, "0"); chocChip.setMaxAge(365 * 24 * 60 * 60); response.addCookie(chocChip); return 1; } } else { double d = Math.random(); d = d * (double)num; j = 0; while (j < d) ++j; if (j == 0) ++j; if (L.equals("e")) { chocChip = new Cookie(L, e[--j][0]); chocChip.setMaxAge(365 * 24 * 60 * 60); response.addCookie(chocChip); } if (L.equals("m")) { chocChip = new Cookie(L, m[--j][0]); chocChip.setMaxAge(365 * 24 * 60 * 60); response.addCookie(chocChip); } if (L.equals("h")) { chocChip = new Cookie(L, h[--j][0]); chocChip.setMaxAge(365 * 24 * 60 * 60); response.addCookie(chocChip); } return j; } } %> <% cookies = request.getCookies(); for (int u=0;u <%=HTMLtitle%>
<% } else if ((submitted != null) && (Replay == null)) { puzzlenum = 0; for (j = 0;j < nume;j++) { if ( puzzleid.equals(e[j][0]) ) { soln = e[j][2]; j = nume; puzzlenum = 1; Level = "easy"; } } if (puzzlenum == 0) { for (j = 0;j < numm;j++) { if (puzzleid.equals(m[j][0])) { soln = m[j][2]; j = numm; puzzlenum = 1; Level = "medium"; } } } if (puzzlenum == 0) { for (j = 0;j < numh;j++) { if (puzzleid.equals(h[j][0])) { soln = h[j][2]; j = numh; puzzlenum = 1; Level = "hard"; } } } // if (soln.equals(submitted) ) { // s = "Congratulations
You solved your puzzle in  "; // } else { // s = "The solution is not correct"; // } HTMLtitle = Level + " Sudoku"; %> <%=HTMLtitle%>
<% if (soln.equals(submitted) ) { %>
<%=duration%>
<% } else { %>
<% } %>
<%} else { // gks added response in call lines here puzzlenum = 0; if (puzzle.equals("easy") ) { puzzlenum = GetRandom( response, "e"); puzzle = e[puzzlenum][1]; puzzleid = e[puzzlenum][0]; HTMLtitle = "Easy Sudoku"; Level = "easy";} if (puzzle.equals("medium") ) { puzzlenum = GetRandom( response, "m"); puzzle = m[puzzlenum][1]; puzzleid = m[puzzlenum][0]; HTMLtitle = "Medium Sudoku"; Level = "medium";} if (puzzle.equals("hard") ) { puzzlenum = GetRandom( response, "h"); puzzle = h[puzzlenum][1]; puzzleid = h[puzzlenum][0]; HTMLtitle = "Hard Sudoku"; Level = "hard";} if (PreviousDate.equals("a")) { s = ""; } else { s="flagreset=true; d = new Date(); d.setTime("+PreviousDate+");"; } %> <%=HTMLtitle%> <% if (Replay != null) { %> <% } else { %> <% } %>
SUDOKU To play Sudoku: complete the grid so there there is 1 - 9 in every row, column and 3x3 block. Use only logic to solve, no maths required!
Time:  
<% } %>