saisie1.pm untested

filter: Statementstmt 0.0% 0 / 113 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 236 CC 25 SCAR 64.0
CC
25
Cov
0%
saisie1
650.0
convertchiffre
2.0
BEGIN
2.0
CRAP 602.0
1 #* Copyright (C) 2008 Christian Guine
2 # * This program is free software; you can redistribute it and/or modify it
3 # * under the terms of the GNU General Public License as published by the Free
4 # * Software Fondation; either version 2 of the License, or (at your option)
5 # * any later version.
6 # * This program is distributed in the hope that it will be useful, but WITHOUT
7 # * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8 # * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
9 # * more details.
10 # * You should have received a copy of the GNU General Public License along with
11 # * this program; if not, write to the Free Software Foundation, Inc., 59
12 # * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13 # */
14 # saisie1.pm treatement of seized modifications
15 # function = "S" ==> solution
16 # function = "R" ==> resolution
17 # function = "C" ==> grid creation
18 # function = "T" ==> seizure of grid
19 # function = "V" ==> seizure of solution
20 sub saisie1 {
21 use Games::Sudoku::sudokuprincipal;
22 #print "saisie1 trait= " . $trait . "\n";
23 $erreur_saisie = 0;
24 $#wprecarre = -1;
25 # Save of context
26 for ($i = 0; $i < $nbcase; $i++) {
27 for ($j = 0; $j < $nbcase; $j++) {
28 for ($k = 0; $k < $nbcase; $k++) {
29 $wprecarre[$i][$j][$k] = $precarre[$i][$j][$k];
30 }
31 }
32 }
33
34 for ($i = 0; $i < $nbcase; $i++) {
35 for ($j = 0; $j < $nbcase; $j++) {
36 my $trouve = "0";
37 for (my $k1 = 0; $k1 < $nbcase; $k1++) {
38 # we seek if a square is found
39 #print " s " . $wprecarre[$i][$j][$k1];
40 if ($wprecarre[$i][$j][$k1] ne "P"
41 and $wprecarre[$i][$j][$k1] ne " "
42 ) {
43 $trouve = "1";
44 #print "saisie1 trouve $i $j $k1\n";
45 }
46 }
47 if ($trouve eq "0") { # if not found
48 if ($trait eq "T" or $trait eq "V") { # seizure
49 #print "saisieaaa $i $j\n";
50 if ($dessin ne "animaux" and $dessin ne "couleurs") {
51 my $b = $entrycarre[$i][$j][0]->Entry;
52 $valeurw = $entrycarre[$i][$j][0]->get;
53 if ($dessin eq "lettres") {
54 # delete spaces beginning and end
55 $valeurw =~ s/^\s+//;
56 #print ("saisie lettre " . $valeurw . "\n");
57 $valeurw = convertchiffre($valeurw);
58 }
59 } else {
60 if ($i == $idessin and $j == $jdessin) {
61 $valeurw = $valdessin;
62 } else {
63 $valeurw = "";
64 }
65 }
66 # delete spaces beginning and end
67 $valeurw =~ s/^\s+//;
68 if ($valeurw eq "A" or $valeurw eq "a") {
69 $valeurw = 10;
70 }
71 if ($valeurw eq "B" or $valeurw eq "b") {
72 $valeurw = 11;
73 }
74 if ($valeurw eq "C" or $valeurw eq "c") {
75 $valeurw = 12;
76 }
77 if ($valeurw eq "D" or $valeurw eq "d") {
78 $valeurw = 13;
79 }
80 if ($valeurw eq "E" or $valeurw eq "e") {
81 $valeurw = 14;
82 }
83 if ($valeurw eq "F" or $valeurw eq "f") {
84 $valeurw = 15;
85 }
86 if ($valeurw eq "G" or $valeurw eq "g") {
87 $valeurw = 16;
88 }
89 if ($valeurw > 0 and $valeurw < ($nbcase + 1)) { # if number is correct
90 # There is a seizure
91 $erreur_aide = 0;
92 if ($aide == 1) {
93 if ($precarres[$i][$j][$valeurw - 1] ne "C") {
94 $erreur_aide = 1;
95 for (my $k1 = 0; $k1 < $nbcase; $k1++) {
96 if ($precarres[$i][$j][$k1] ne " " and
97 $precarres[$i][$j][$k1] ne "P")
98 {
99 $bonnevaleur = $k1 + 1;
100 last;
101 }
102 }
103 }
104 }
105 if (($precarre[$i][$j][$valeurw - 1] ne "P")
106 or $erreur_aide == 1) {
107 $erreur_saisie = 1;
108 } else {
109 if ($trait eq "V") { # we are seizing
110 # a solution
111 $precarre[$i][$j][$valeurw - 1] = "C";
112 $entree = "C";
113 } else { # we are seising a problem
114 $precarre[$i][$j][$valeurw - 1] = "S";
115 $entree = "S";
116 }
117 $ligne = $i;
118 $colonne = $j;
119 $valeur = $valeurw - 1;
120 $endroit = "";
121 modif_tableau($entree);
122 }
123 }
124 } else { # we are not seizing
125 for ($k = 0; $k < $nbcase; $k++) {
126 #print "i= " . $i . " j= " . $j . " k= " . $k . "\n";
127 if (exists ($entrycarre[$i][$j][$k])) {
128 my $b = $entrycarre[$i][$j][$k]->Entry;
129 $valeurw = $entrycarre[$i][$j][$k]->get;
130 # delete spaces beginning and end
131 $valeurw =~ s/^\s+//;
132 #print " e " . $valeurw;
133 if ($wprecarre[$i][$j][$k] eq "P") {
134 $wcarre = $k + 1;
135 } else {
136 $wcarre = " ";
137 }
138 if ($valeurw != $wcarre) {
139 #print (" modif i= " . $i . " j= " . $j . " k= " . $k );
140 $precarre[$i][$j][$k] = "S";
141 $ligne = $i;
142 $colonne = $j;
143 $valeur = $k;
144 $entree = "S";
145 $endroit = "";
146 modif_tableau($entree);
147 }
148 }
149 }
150 }
151 }
152 }
153 }
154 #print "fin saisie1 $erreur_saisie\n";
155 if ($trait eq "T") {
156 affichage_grille('T');
157 } elsif ($trait eq "V") {
158 verif_fin();
159 affichage_grille('V');
160 } else {
161 solution();
162 }
163 }
164 1;
165  
166 sub convertchiffre { # Conversion letter in number
167 my ($lettre, $code) = @_;
168 my %chif = ('A','1','B','2','C','3','D','4','E','5','F','6','G','7','H','8','I','9',
169 'J','10','K','11','L','12','M','13','N','14','O','15','P','16',
170 'a','1','b','2','c','3','d','4','e','5','f','6','g','7','h','8','i','9',
171 'j','10','k','11','l','12','m','13','n','14','o','15','p','16');
172 my $chiffre = $chif{$lettre};
173 #print ("convertchiffre " . $chiffre . " " . $lettre . "\n");
174 return $chiffre;
175 }