Ok I re-wrote it so it would work (I think).
This is the current bot code for my function:
function playBot(colour)
currentTurn = 1
msg = colorNames[1] .. "'s Turn"
local blockPlaced = false
for x = 1, 18 do
for y = 1, 13 do
for p = 1, playersMaximum do
if tab[x+1][y] == p and tab[x+2][y] == p and tab[x+3][y] == p and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x+4][y] == 0 then
tab[x+4][y] = colour
blockPlaced = true
end
elseif tab[x][y+1] == p and tab[x][y+2] == p and tab[x][y+3] == p and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x][y+4] == 0 then
tab[x][y+4] = colour
blockPlaced = true
end
elseif tab[x+1][y+1] == p and tab[x+2][y+2] == p and tab[x+3][y+3] == p and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x+4][y+4] == 0 then
tab[x+4][y+4] = colour
blockPlaced = true
end
else
-- Currently working on (this time)
end
end
end
end
end
Fixed
And I wanted a compacted switch between turns, but accidently brocken it. Here is it: Any compact fix?
if currentTurn == 1 then if playersPlaying == 1 then playBot(2) else currentTurn = 2 end end for p = 2, playersMaximum-1 do if playersPlaying == p then currentTurn = 1 elseif playersPlaying > p then currentTurn = p + 1 end end --[[elseif currentTurn == 2 then if playersPlaying == 2 then currentTurn = 1 elseif playersPlaying > 2 then currentTurn = 3 end elseif currentTurn == 3 then if playersPlaying == 3 then currentTurn = 1 elseif playersPlaying > 3 then currentTurn = 4 end elseif currentTurn == 4 then if playersPlaying == 4 then currentTurn = 1 elseif playersPlaying > 4 then currentTurn = 5 end elseif currentTurn == 5 then if playersPlaying == 5 then currentTurn = 1 elseif playersPlaying > 5 then currentTurn = 6 end]] if currentTurn == playersMaximum then if playersPlaying == playersMaximum then currentTurn = 1 elseif playersPlaying > playersMaximum then currentTurn = currentTurn + 1 -- impossible winner = 0 end end ```
Function “playBot” in v4
function playBot(colour)
currentTurn = 1
local blockPlaced = false
for x = 1, 18 do
for y = 1, 13 do
for p = 1, playersMaximum do
-- Important secure// 3+ blocks in row (enemy)
if tab[x+1][y] == p and tab[x+2][y] == p and tab[x+3][y] == p and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x+4][y] == 0 then
tab[x+4][y] = colour
blockPlaced = true
end
elseif tab[x][y+1] == p and tab[x][y+2] == p and tab[x][y+3] == p and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x][y+4] == 0 then
tab[x][y+4] = colour
blockPlaced = true
end
elseif tab[x+1][y+1] == p and tab[x+2][y+2] == p and tab[x+3][y+3] == p and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x+4][y+4] == 0 then
tab[x+4][y+4] = colour
blockPlaced = true
end
-- Win// 3+ blocks in row. (friend)
elseif tab[x+1][y+1] == colour and tab[x+2][y+2] == colour and tab[x+3][y+3] == colour and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x+4][y+4] == 0 then
tab[x+4][y+4] = colour
blockPlaced = true
end
elseif tab[x][y+1] == colour and tab[x][y+2] == colour and tab[x][y+3] == colour and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x][y+4] == 0 then
tab[x][y+4] = colour
blockPlaced = true
end
elseif tab[x+1][y] == colour and tab[x+2][y] == colour and tab[x+3][y] == colour and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x+4][y] == 0 then
tab[x+4][y] = colour
blockPlaced = true
end
-- Secure// 2+ blocks in row.
elseif tab[x+1][y] == p and tab[x+2][y] == p and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x+3][y] == 0 then
tab[x+3][y] = colour
blockPlaced = true
end
elseif tab[x+1][y+1] == p and tab[x+2][y+2] == p and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x+3][y+3] == 0 then
tab[x+3][y+3] = colour
blockPlaced = true
end
elseif tab[x][y+1] == p and tab[x][y+1] == p and not blockPlaced then
if tab[x][y] == 0 then
tab[x][y] = colour
blockPlaced = true
elseif tab[x][y+3] == 0 then
tab[x][y+3] = colour
blockPlaced = true
end
else
end
end
if not blockPlaced then
--playBot(colour)
end
end
end
end
In v4 coming
- Fairy Theme
- Duel Mode
- Some Bug fixes
- AI - First Bot Productions.
Update v4
https://github.com/TokOut/InOneClass/blob/master/Win5/version4.lua
- Duel Mode (Entire) - A timer for the entire game. (Every player has got his own timer.)
- Duel Mode (Regenerated) - A timer for every round new.
- Fairy Theme (with Sound, Temporary) - With relaxing music.
- Player Elimination: If the timer gets lower then 0, the player will be eliminated from the game. This is a part from the Duel Mode added.
Known Bugs for this version (Please suggest fixes.)
- Lonely player against computer (Players count: 1) was disabled accidently. Sorry.
- There are 100 Seconds in one minute for Duel Mode (Entire). There aren’t 60 miliseconds in one second, there are 100, that’s why Duel Mode (Regenerated) works.
Coming in v5
- (Maybe): Finally Bots!
- Fix Above listed Bugs.
- Add Settings, for example: > Allow placing blocks on already blocks (but of course not on just placed ones, able to set to: “Can’t place blocks on last XX moves, else you can.”)
- (Maybe): 10 New Sub-Colors (Cyan, Brown, …)
I have fixed above listed not working Bot Mode in Code. Does anyone has a good bot code?
I dont have any bot code, but I’ll try to write some bot code for you!