Question: function Solution = SudokuNxN ( A , T ) % Get the size of the Sudoku grid gridSize = size ( A , 1 )
function Solution SudokuNxNA T
Get the size of the Sudoku grid
gridSize sizeA;
boxSize sqrtgridSize; Assumes the grid is a perfect square
Initialize player existence and move arrays
players zerosgridSize gridSize, ;
for i :gridSize
for j :gridSize
if Ai j
playersi j; Mark cell as active if it's empty
end
end
end
S ;
N ;
maxIterations ;
while S && N maxIterations
Each player picks a move according to the learning rule
for i :gridSize
for j :gridSize
if playersi j
Test A;
payoffs zeros gridSize;
for move :gridSize
Testi j move;
payoffsmove MatchesNxNTest i j gridSize, boxSize;
end
playersi j PickMovepayoffs T;
end
end
end
Update the matrix
for i :gridSize
for j :gridSize
if playersi j
Ai j playersi j;
end
end
end
T T ; Reduce the temperature
S IsSolvedNxNA gridSize, boxSize; Check if the puzzle is solved
N N ;
end
Solution A;
if N maxIterations
fprintfFail
;
elseif S
fprintfResolved in d iterations at temp f
N T;
end
end
function M MatchesNxNA i j gridSize, boxSize
M ;
Check the row
for n :gridSize
if n ~ j && Ai j Ai n
M M ;
end
end
Check the column
for n :gridSize
if n ~ i && Ai j An j
M M ;
end
end
Check the subbox
boxRow flooriboxSizeboxSize ;
boxCol floorjboxSizeboxSize ;
for n boxRow:boxRowboxSize
for m boxCol:boxColboxSize
if ~n i && m j && Ai j An m
M M ;
end
end
end
end
function S IsSolvedNxNA gridSize, boxSize
S ; Assume solved unless a conflict is found
for i :gridSize
for j :gridSize
if MatchesNxNA i j gridSize, boxSize
S ; If any conflicts, mark as unsolved
return;
end
end
end
end
function move PickMovepayoffs T
annealed expT payoffs; Calculate annealed probabilities
sumAnnealed sumannealed;
probabilities annealed sumAnnealed; Normalize to create probability distribution
r rand;
cumProb ;
move ; Default move if none other selected
for k :lengthpayoffs
cumProb cumProb probabilitiesk;
if r cumProb
move k;
break;
end
end
end
Test with an example Sudoku puzzle and temperature
A
;
;
;
;
;
;
;
;
;
;
Add more rows to complete the grid
;
T ;
Solution SudokuNxNA T;
dispSolution;
Extend it to larger settings
Implement fictitious play in Matlab for rockpaperscissors game, show that it converges to the equilibrium.
Then, extend it to rockpaperscissors, superman, kryptonite game and demonstrate again that it converges to the equilibrium
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
