My first game in Picotron !!
Hello there :3
I recently got this workstation and wanted to make something with it.
So why not make a little simple game to start with !!
Controls
For now, you can play only with the mouse. But I think I will add some other control in the future.
Feature
It's a little bit basic for now. But if you install it with load #picotoe you will be able to personalize the color of the X and O symbol. (You can find it in the sprite tab)
However, I want to try some botfeature. So don't hesitate to follow and keep in touch with future progress.
Nice work! It's a great idea to add a bot player.
Another feature idea: add a score (how many games were won by X and by O).
Welcome to the community :)
Thanks @pck404 !! Yesterday I worked on a refactoring of all the code (so that it no longer depends on a fixed value, but can be enlarged to any desired shape).
I've enlarged the window to allow text to be written on top to integrate a victory counter (and potentially a choice of symbol), but I confess I don't yet know how I intend to indicate the scores. Or how to save them.
However, I intend to continue this little project for a while! This is the first time I've done lua if you don't count some experience on Pico-8. I had already done javascript and other things. I must admit that I have a problem with table ‘cloning’. I have the impression that whatever I do, lua just assigns a pointer to my variables instead of their value.
@moee "I must admit that I have a problem with table 'cloning'. I have the impression that whatever I do, lua just assigns a pointer to my variables instead of their value"
Yes, that's how tables work in Lua. it can be helpful sometimes, but it can also get in your way if you're not expecting it. Here is a useful function to get around this:
function cpy_obj(obj)
local cpy={}
for key,val in pairs(obj) do
cpy[key]=val
end
return cpy
end |
Here's a snippet of code to test the above function:
function _draw()
cls()
table_a={1,3,6} -- table_a is a pointer to {1,3,6}
table_b=table_a -- table_b is the same pointer as table_a
table_b[4]=10 -- also affects table_a
print(table_a[4]==10) -- should be true
table_c=cpy_obj(table_a) -- table_c is now a different table
print(table_a[2]==table_c[2]) -- should be true
table_c[5]=15 -- does not affect table_a
print(table_a==nil) -- should be true
end |
Thanks @Kaius, I had tried this before, but it doesn't work with multi-level tables.
So I make it recursive to do it correctly!
ta = {
{0},
{1}
}
function _draw()
cls()
tb = ta
tb[1][1] = 3
print("ta:"..ta[1][1])
print("tb:"..tb[1][1])
print("====")
tc = table.clone(ta)
tc[1][1] = 5
print("ta:"..ta[1][1])
print("tb:"..tb[1][1])
print("tb:"..tc[1][1])
end
--
-- Helper fonction to clone tables
--
-- param : table t - the table to be cloned
-- return : table - the table cloned
--
function table.clone(t)
-- c: cloned table
local c={}
-- k: key, v: value
for k,v in pairs(t) do
if(type(v)=="table") then
c[k]=table.clone(v)
else
c[k]=v
end
end
return c
end |
Awesome! It’s always a wonder to see such classic games ported to Picotron. Can’t wait to see more!
[Please log in to post a comment]




