0% found this document useful (0 votes)
55 views6 pages

A1Viewcontroller.M // Suduku - Logic // // Created by A1Brains Infotech On 16/07/14.

This document contains code for a Sudoku logic game controller class called A1ViewController. It includes methods for generating random Sudoku boards, checking for valid moves, and updating the board state over time with a timer. The class initializes properties like a move counter, terminate flag, and timer. It has methods to generate random numbers, find unique positions, and recursively build the Sudoku board representation.

Uploaded by

Moinuddin Girach
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views6 pages

A1Viewcontroller.M // Suduku - Logic // // Created by A1Brains Infotech On 16/07/14.

This document contains code for a Sudoku logic game controller class called A1ViewController. It includes methods for generating random Sudoku boards, checking for valid moves, and updating the board state over time with a timer. The class initializes properties like a move counter, terminate flag, and timer. It has methods to generate random numbers, find unique positions, and recursively build the Sudoku board representation.

Uploaded by

Moinuddin Girach
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 6

//

// A1ViewController.m
// SUDUKU_LOGIC
//
// Created by A1brains Infote! on 1"/#$/1%.
// Co&yri'!t () *#1% A1brains Infote!. All ri'!ts reser+ed.
//
,im&ort -A1ViewController.!-
.interfae A1ViewController ()
.&ro&erty (nonatomi/assi'n)0OOL terminate1
.&ro&erty (nonatomi/assi'n) int o2nt1
.&ro&erty (nonatomi/stron') 3S4imer 5timer1
.end
.im&lementation A1ViewController
6 (+oid)+iewDidLoad
7
8s2&er +iewDidLoad91
_o2nt : #1
UI02tton 5btn : 8UI02tton b2tton;it!4y&e<UI02tton4y&eC2stom91
8btn set=rame<CG>et?a@e(1##/ 1##/ *##/ A#)91
8btn set4itle<.-Generate- forState<UIControlState3ormal91B
8btn set4itleColor<8UIColor bla@Color9
forState<UIControlState3ormal91
8btn add4ar'et<self ation<.seletor('enerateS2d2@2)
forControlC+ents<UIControlC+ent4o2!U&Inside91
8self.+iew addS2b+iew<btn91

// Do any additional set2& after loadin' t!e +iew/ ty&ially from
a nib.
D
6 (+oid)'enerateS2d2@2 7
_o2nt : #1
_terminate : 3O1
3SLo'(.-Ed-/_o2nt)1
_timer : 83S4imer s!ed2led4imer;it!4imeInter+al<* tar'et<self
seletor<.seletor(terminateFroess) 2serInfo<nil re&eats<3O91

3S?2tableArray 5arr : 883S?2tableArray allo9
init;it!Ca&aity<G91

for (int i : #1 i H G1 iII) 7
_o2ntII1
8arr addObJet<883S?2tableArray allo9
init;it!Array<.8.-#-/.-#-/.-#-/.-#-/.-#-/.-#-/.-#-/.-#-/.-#-99
91
D
/5
for (int i : # 1 i H G1 iII) 7
8arr addObJet<8self reate>andom3omber991
D
5/
for (int i : #1 i H G1 iII) 7
_o2ntII1
for (int J : #1 J H G1 JII) 7
_o2ntII1
3S?2tableArray 5arr4 : 83S?2tableArray array;it!Array<
8self reate>andom3omber991
if (i :: # KK J :: #) 7
int rand1 : ar%random() E G1
id old : 8arr4 obJetAtIndeL<rand191
8arr4 re&laeObJetAtIndeL<rand1 wit!ObJet<8arr4
obJetAtIndeL<#991
8arr4 re&laeObJetAtIndeL<# wit!ObJet<old91
D
int n2m : 8self reateUniM3oIn>ow<i andCol2mn<J inArray<arr
wit!So2re<arr4 wit!Val2e<#91
if (n2m :: 61) 7
if (_o2nt N *#####) 7
brea@1
D
8arr re&laeObJetAtIndeL<i wit!ObJet<883S?2tableArray
allo9
init;it!Array<.8.-#-/.-#-/.-#-/.-#-/.-#-/.-#-/.-#-/.-#-/.-#-99
91
J : 611
ontin2e1
D
88arr obJetAtIndeL<i9 re&laeObJetAtIndeL<J wit!ObJet<
83S32mber n2mber;it!Int<n2m991
D
if (_o2nt N *#####) 7
brea@1
D
D

3SLo'(.-Ed-/_o2nt)1

for (int i : #1 i H G1 iII) 7
3SLo'(.-E.-/88arr obJetAtIndeL<i9
om&onentsOoined0yStrin'<.-/-9)1
D

if (_timer) 7
8_timer in+alidate91
D
if (_o2nt N *#####) 7
8self 'enerateS2d2@291
D
8self reateS2do@2<arr wit!L+l<#91
D
6(+oid)terminateFroess 7
_terminate : PCS1
3SLo'(.-Froess terminated-)1
if (_timer) 7
8_timer in+alidate91
D
D
6(int)reateUniM3oIn>ow<(int)row andCol2mn<(int)ol2mn inArray<
(3SArray 5)arr wit!So2re<(3SArray 5)arrSo2re wit!Val2e<(int)+al 7
int Qll3o : 88arrSo2re obJetAtIndeL<+al9 intVal2e91

0OOL isUniM : 3O1

for (int i : #1 i H G1 iII) 7
_o2ntII1
if (Qll3o :: 888arr obJetAtIndeL<row9 obJetAtIndeL<i9 intVal2e9)
7
isUniM : 3O1
brea@1
D else 7
isUniM : PCS1
D
D

if (isUniM) 7
for ( int J : #1 J H G1 JII) 7
_o2ntII1
if (Qll3o :: 888arr obJetAtIndeL<J9 obJetAtIndeL<ol2mn9
intVal2e9) 7
isUniM : 3O1
brea@1
D else 7
isUniM : PCS1
D
D
D

if (isUniM) 7
int rowCol : 8self sM2arefor>ow<row andCol2mn<ol2mn91
int ol1 : rowCol E 1#1
int row1 : (rowCol 6 ol1) / 1#1

3S?2tableArray 5arr4em& : 883S?2tableArray allo9 init91

for (int l : row11 l H row1 I R1 lII) 7
_o2ntII1
for (int m : ol11 m H ol1 I R1 mII) 7
_o2ntII1
8arr4em& addObJet<88arr obJetAtIndeL<l9
obJetAtIndeL<m991
D
D

for ( int n : #1 n H G1 nII) 7
_o2ntII1
if (Qll3o :: 88arr4em& obJetAtIndeL<n9 intVal2e9) 7
isUniM : 3O1
brea@1
D else 7
isUniM : PCS1
D
D
arr4em& : nil1
D
if (isUniM) 7
ret2rn Qll3o1
D else if(SisUniM KK +al :: T) 7
ret2rn 611
Delse 7
ret2rn 8self reateUniM3oIn>ow<row andCol2mn<ol2mn
inArray<arr wit!So2re<arrSo2re wit!Val2e<+al I 191
D
D
6 (int)sM2arefor>ow<(int)row andCol2mn<(int)ol2mn 7
int row1 : (row 6 (row E R))1
int ol1 : (ol2mn 6 (ol2mn E R))1
ret2rn (row1 5 1#) I ol11
D
6(3SArray 5)reate>andom3omber7
3S?2tableArray 5arr : 883S?2tableArray allo9 init91
for (int i : #1 i H G1 iII) 7
_o2ntII1
if (i :: #) 7
8arr addObJet<83S32mber n2mber;it!Int<random() E 1#991
D else 7
8arr addObJet<83S32mber n2mber;it!Int<8self
reateUniM2e32mberInSet<arr9991
D
D
ret2rn arr1
D
6 (int)reateUniM2e32mberInSet<(3SArray 5)arr 7
0OOL is2niM : 3O1
int random32mber : random() E 1#1
for (3S32mber 5n2m in arr) 7
_o2ntII1
if (random32mber :: 8n2m intVal2e9) 7
is2niM : 3O1
brea@1
D else 7
is2niM : PCS1
D
D
if (is2niM KK (random32mber N #)) 7
ret2rn random32mber1
D else 7
ret2rn 8self reateUniM2e32mberInSet<arr91
D
D
6 (+oid)did>eei+e?emory;arnin'
7
8s2&er did>eei+e?emory;arnin'91
// Dis&ose of any reso2res t!at an be rereated.
D
6 (int)QndUniFlaeinarr<(3S?2tableArray 5)arr 7
int loation : ((ar%random() EG) 5 1#) I (ar%random() E G)1
0OOL isUniM : PCS1
for (int i : #1 i H 8arr o2nt91 iII) 7
if (loation :: 88arr obJetAtIndeL<i9 intVal2e9) 7
isUniM : 3O1
brea@1
D else 7
isUniM : PCS1
D
D

if (isUniM) 7
ret2rn loation1
D else 7
ret2rn 8self QndUniFlaeinarr<arr91
D
D
6 (+oid)reateS2do@2<(3SArray 5)arr wit!L+l<(int)le+el7
3S?2tableArray 5QnalArr : 883S?2tableArray allo9 init91
for (int i : #1 i H G 5(le+el I %)1 iII) 7
8QnalArr addObJet<83SStrin' strin';it!=ormat<.-Ed-/8self
QndUniFlaeinarr<QnalArr9991
D

3S?2tableArray 5arr* : 83S?2tableArray array;it!Array<arr91
for (int i : #1 i H 8QnalArr o2nt91 iII) 7
int ol : 88QnalArr obJetAtIndeL<i9 intVal2e9 E 1#1
int row : (88QnalArr obJetAtIndeL<i9 intVal2e9 6 ol) /1#1
88arr* obJetAtIndeL<row9 re&laeObJetAtIndeL<ol
wit!ObJet<.-#-91
D

3SLo'(.-Bn-)1

for (int i : #1 i H G1 iII) 7
3SLo'(.-E.-/88arr* obJetAtIndeL<i9
om&onentsOoined0yStrin'<.-/-9)1
D

D
.end

You might also like