Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
65
Task/Flipping-bits-game/MiniScript/flipping-bits-game.mini
Normal file
65
Task/Flipping-bits-game/MiniScript/flipping-bits-game.mini
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// Flipping Bits game.
|
||||
// Transform a start grid to an end grid by flipping rows or columns.
|
||||
|
||||
size = 3
|
||||
|
||||
board = []
|
||||
goal = []
|
||||
for i in range(1,size)
|
||||
row = []
|
||||
for j in range(1,size)
|
||||
row.push (rnd > 0.5)
|
||||
end for
|
||||
board.push row
|
||||
goal.push row[0:]
|
||||
end for
|
||||
|
||||
flipRow = function(n)
|
||||
for j in range(0, size-1)
|
||||
board[n-1][j] = not board[n-1][j]
|
||||
end for
|
||||
end function
|
||||
|
||||
flipCol = function(n)
|
||||
for i in range(0, size-1)
|
||||
board[i][n-1] = not board[i][n-1]
|
||||
end for
|
||||
end function
|
||||
|
||||
flipAny = function(s)
|
||||
s = s[0].upper
|
||||
if s >= "A" then flipCol s.code - 64 else flipRow val(s)
|
||||
end function
|
||||
|
||||
for scramble in range(20)
|
||||
if rnd < 0.5 then flipRow ceil(rnd*size) else flipCol ceil(rnd*size)
|
||||
end for
|
||||
|
||||
solved = function()
|
||||
for i in range(0, size-1)
|
||||
for j in range(0, size-1)
|
||||
if board[i][j] != goal[i][j] then return false
|
||||
end for
|
||||
end for
|
||||
return true
|
||||
end function
|
||||
|
||||
moveCount = 0
|
||||
while true
|
||||
print " CURRENT:" + " "*(4+size*3) + "GOAL:"
|
||||
for i in range(1,size)
|
||||
s = i + " " + str(board[i-1])
|
||||
s = s + " "*(3+size*3) + str(goal[i-1])
|
||||
print s
|
||||
end for
|
||||
s = " "
|
||||
for i in range(1,size)
|
||||
s = s + char(64+i) + " "
|
||||
end for
|
||||
print s
|
||||
if solved then break
|
||||
moveCount = moveCount + 1
|
||||
inp = input("Move " + moveCount + "? ")
|
||||
flipAny(inp)
|
||||
end while
|
||||
print "You did it!"
|
||||
Loading…
Add table
Add a link
Reference in a new issue