2
import QtQuick.LocalStorage 2.0
6
JsConfiguration{id:dbConf}
9
var numberOfColors = dbConf.getNumberOfColors();
10
var numberOfFields = dbConf.getNumberOfFields();
12
var db = dbAccess.getDatabase();
14
for(var i=0;i<numberOfFields;i++){
15
db.transaction(function(tx) {
16
tx.executeSql('INSERT OR REPLACE INTO solution VALUES (?,?);', [i,Math.round(Math.random()*(numberOfColors-1))+1]);
23
return hidden.compare(hidden.getSolution(),getTry());
27
for(var i=0;i<aTry.length;i++){
28
if(aTry[i]===0) return false;
35
for(var i=0;i<dbConf.getNumberOfFields();i++){
36
console.log(i+":"+res[i]);
37
if(res[i]!==2){return false; }
45
function compare(Solution,tryCombination) {
46
var numberOfFields=dbConf.getNumberOfFields();
47
var numberOfColors=dbConf.getNumberOfColors();
48
var result = new Array(numberOfFields);
49
var colors = new Array(numberOfColors+1);
50
for(var k=0;k<numberOfFields;k++){
53
var colorsGuessed = new Array(numberOfColors+1);
55
//console.log("Number of Colors: "+numberOfColors+" Number of Fields:"+numberOfFields);
56
for(k=0;k<numberOfColors+1;k++){
60
for (var i = 0; i < numberOfFields; i++) {
61
colors[Solution[i]]++;
62
//console.log("Colors of Solution: "+Solution[i]);
65
for (i = 0; i < numberOfFields; i++) {
66
//console.log("Colors Guessed: "+tryCombination[i]+","+colorsGuessed[tryCombination[i]]+" colors Solution: "+colors[tryCombination[i]]);
67
if (colorsGuessed[tryCombination[i]] < colors[tryCombination[i]]) {
68
colorsGuessed[tryCombination[i]]++;
69
//console.log("Colors Guessed: "+tryCombination[i]);
74
for ( i = 0; i < tryCombination.length; i++) {
75
if (tryCombination[i] === Solution[i]) {
77
colorsGuessed[tryCombination[i]]--;
79
//console.log("Colors and Position Guessed: "+tryCombination[i]);
82
for ( i = 0; i < tryCombination.length && j < numberOfFields; i++) {
83
if (colorsGuessed[tryCombination[i]] > 0) {
84
colorsGuessed[tryCombination[i]]--;
93
function setTryAt(tIndex,value){
94
var db = dbAccess.getDatabase();
96
db.transaction(function(tx) {
97
var rs = tx.executeSql('INSERT OR REPLACE INTO currentTry VALUES (?,?);', [tIndex,value]);
98
if (rs.rowsAffected > 0) {
107
function getSolution(){
108
var res = new Array(dbConf.getNumberOfFields());
109
for(var i=0;i<dbConf.getNumberOfFields();i++){
110
res[i]=getSolutionAt(i);
114
function getSolutionAt(tIndex) {
115
var db = dbAccess.getDatabase();
117
db.transaction(function(tx) {
118
var rs = tx.executeSql('SELECT value FROM solution WHERE tIndex=?;', [tIndex]);
119
if (rs.rows.length > 0) {
120
res = rs.rows.item(0).value;
133
function nextTryAt(tIndex){
134
var res = getTryAt(tIndex);
136
if(res>dbConf.getNumberOfColors())
140
hidden.setTryAt(tIndex,res);
143
function getTryAt(tIndex) {
144
var db = dbAccess.getDatabase();
146
db.transaction(function(tx) {
147
var rs = tx.executeSql('SELECT value FROM currentTry WHERE tIndex=?;', [tIndex]);
148
if (rs.rows.length > 0) {
149
res = rs.rows.item(0).value;
158
var res = new Array(dbConf.getNumberOfFields());
159
for(var i=0;i<dbConf.getNumberOfFields();i++){
161
//console.log("Try at:"+i+" : "+res[i]);
167
var res = new Array(dbConf.getNumberOfFields());
168
for(var i=0;i<dbConf.getNumberOfFields();i++){
169
hidden.setTryAt(i,0);