I Put My Childhood Games On-Chain | Ōkinoko Ināro

in HiveDevs9 months ago

> Free Games, Fair Rules, Optional Thrill <

The Story Before The Code

Tic Tac - Tic Tac - Tic Tac.... The mechanical kitchen clock is ticking while it smells like cabbage rolls and mashed potatoes. The radio plays German Schlager music, and from another room, I hear my grandpa arguing with a German TV host. I am sitting at the kitchen table playing Tic Tac Toe on paper with my lovely grandma. I doubt she lost so often without cheating. This happened many times in my early childhood when my grandparents took care of me to let my parents breathe, or just so we could share time together.

Later, I discovered Connect 4 (here in Germany "Vier gewinnt") as my new favorite game and battled my brother countless times until falling asleep. He never let me win, though.

Then one day in the mid 90s, my dad brought home one of the first (still not very affordable) personal computers, and suddenly everything changed. My brother got sucked into DOS and later Windows gaming, and I followed his example even though I was just too young to understand some games. We had countless floppy disks, computer magazines with gaming CDs, and walkthrough/cheat books floating around in our room, but there was still something very big to happen soon.

The internet became a thing, and I was addicted to designing my Myspace page, writing in chat rooms, playing browser games, and reading Wikipedia. The days with simple but fun physical games slowly faded into the background. Sad? No - maybe some nostalgia hitting while writing this, but:

Look At Us!

We are on a freaking blockchain in the year 2025 with a community I never imagined to be a part of, and I am writing a post about my 2nd smart contract?! My past child-self would be looking up to me now - proud but with big question signs in his eyes, haha

After the internet came, I kind of forgot about Tic Tac Toe on paper until a few weeks (or maybe even months) ago. Because then I started preparing the small digital pre-Christmas gift, I am writing this post for: Playing my childhood games on the Magi network - 100% free! Let me introduce:




- Ōkinoko Ināro -


This is an on-chain dual player game collection focused on classic “in-a-row” games. That's where the awesome name is coming from ;) All games are turn-based, deterministic, and run directly on the Magi chain.

You can battle other Hivers in:

  • Tic Tac Toe
  • Tic Tac Toe 5 (4 in a row wins)
  • Connect Four / Vier gewinnt
  • Gomoku (exactly 5 in a row wins)
  • Gomoku Freestyle (5 or more in a row wins)
  • Squava (4 in a row wins - 3 in a row loses)



Playing the Games

You can play directly in the browser via: ▶️ Okinoko.io ◀️
But don't you leave now - I have something important to share!

There are Christmas Bonus Gifts!

I have defined some special occurrences/milestones in the game loop, and the first one who reaches such an event will be given 1 HBD. I reserved 20 HBD in total for this giveaway.

There are no visuals for these events, so do not search or wait for them + I will make the gifting manually based on logs, and I will do reputation / multi-account checks, so do not try to cheat ;)

Simply play the game with your main account and get surprised with some extra funds in your Magi wallet! But hurry up because 01.01.26 is the deadline for these prizes. The remaining pot will go to @okinoko for managing your notifications (more on that below).

I hope that Okinoko.io is self-explanatory, but since I see this thing with developer goggles, I will now give you a short introduction about the platform and some details about the games. This weekend I am also going to share a video explaining it again for the "non-reading people" and to spread the word even more.




Connect Wallet

After opening Okinoko.io, you will be greeted with a terminal-style cyberpunkish console application. Welcome to the terminal! All terminal containers are movable/resizable + there is a small menu at the top right corner, where you can discover other visual and auditory settings. Try them out!

To interact with the Magi network, you'll need a Hive account - this is an easy one I guess ^^ Simply log in with Keychain/HiveAuth and get the ball rolling!




Select / Create a Game

After getting lost in the visuals (and probably disabling sound ^^), your next step is to focus again(!) and click on "Enter >". You will land in the contract / function select screen.

On the left are all currently supported contracts, and by clicking on them, you will see functionalities on the right. Ināro and ShinDAO do have special screens, tho.

Our gaming contract is split into various game types. Select one and click on "Next >".


If you open a game type the tab switches automatically to where you probably want to go. With no active game, you will land in the lobby; when there is no game waiting for a player, you will automatically land on the "create" screen.

Here you can set up a (1) name for the game (keep empty when you want a low-RC-transaction) (2) the optional bet, and (3) the optional FMP costs. After filling the inputs (or not), you can hit (4) "Create Game >" and sign the transaction with your wallet.

Speaking of wallet: There is a small but still visible (i) icon next to the amount input field. This will open an important pop-up - read it and think about it ;) (more on that below)




Play the Game

Well, the games are super simple, so you are probably going to know how to play them. (1) Place your field - (2) Send your move to the chain.

There is always a little hint on the left of the board about what goal each game has and when you will lose. Additionally to this you can see whose turn it is and the complete history of the game so far.

As mentioned below: The Gomoku Swap2 opening is a bit more complex if you are new to it. In this case, you are going to find more details about the state the game is in and what has to be done to continue. Read the paragraph "Fairness First (And Why It Matters)" - you got this!




Resign / Timeout

(1) In case you can see your downfall and don't want to watch the winner make their final move, you can resign early. That will save you both time and RC. Tip: Use the resign function if nobody joined your game yet to get your bet back from the contract.

(2) If your opponent is afk for more than 7 days, simply claim the timeout. This makes you automatically the winner of the game, and you will receive the prize pool if present.




Notifications

There's no need to check the game contract every day because you'll receive notifications when something happens in one of your games on your favorite Hive frontend! (mine is ecency btw ;) )

I thought this is a pretty neat way to remind you of your games, even though each notification cost me 0.001 HIVE. I think it is worth having, and maybe someone of you wants to donate some HIVE to @okinoko to make my life easier ;)




Leaderboard / History

For obvious reasons, I have added a leaderboard which is currently split into two different perspectives: "All time" and the more prominent "Current Season". The latter gets nulled every quarter of the year.

Obviously, this is not done at all yet. I will change the season to match actual seasons, and I envision special - maybe sponsored - events and a few more KPIs. For now, the leaderboard has enough potential to keep players engaged and wanting to move up the list.

The history currently is only a list of your games and the outcome. I am planning to visualize the final board setup and more, but that has to wait until next year.




Check your RC

Your Magi RC is important for executing smart contracts, and that's what we do with every step of the game loop, from creating (~2 RC) to making moves (~0.8 RC), and for the final move (~1.5 RC), you will always need your Resource Credits. RC is refilled automatically on Magi based on your current HBD balance, and Hive users have a bonus of 5 RC by default.

I recommend that you put some HBD into your Magi Wallet if you want to interact with contracts on a regular basis. 5-10 HBD is already enough to have a decent gaming experience and for using my other contracts like the Ōkinoko Esukurō formally known and described in detail on my blog as Escrow or the Ōkinoko ShinDAO I am going to cover soon in a separate post.




TX / Blocks Monitor

Especially in the dev phase of the past few weeks, I needed a way to check transactions without leaving my browser tab. I recommend vsc.techcoderx.com for more details, but this simple display was enough for my use case.

That's why I have created and kept this terminal console. There is a list of transactions, block production, and some Magi witness information. In the near future, I am probably going to add some more features to this console.




About Betting (Optional, Always)

While building this, I obviously thought about gambling and had some moral doubts there, but I decided to add it.

The truth is: Web3 games often need financial incentives to take off and stay interesting in these fast-paced times. So I decided on the simple rule that bets are fully optional. I even thought about adding user-specific time limits on betting games, but we are all adults (okay - most of us here) so do what you wanna do. I took the time to add a small (i) icon next to the amount inputs and almost everywhere the word "bet" is shown.

Most of the gambling sites benefit financially from addictive behaviour - Ōkinoko does not: There is no rake, no fee, and no beneficiary in any way for me. Winner takes all. Draws split the pot. That's it!




Fairness First (And Why It Matters)

After adding the initial Tic Tac Toe and Connect 4, my next step was obvious: find more games that follow the same simple 2D in-a-row idea, and I got to the list we have today.

While researching Gomoku, I went deep into old forums and articles discussing fairness. Gomoku (and all the other games on our list) has a well-known imbalance in favor of the first mover. That's why serious tournaments use a special opening rule called Swap2 - and yes, that is fully implemented here. Swap2 removes the usual first-move advantage by adding some initial moves/decisions for both players. It’s a bit more complex, but totally worth it:

  1. The first player puts 2 black (*) and 1 white (@) stones anywhere on the board
  2. The second player has 3 options:
  • stay with their color
  • swap colors
  • put 2 more stones and let the opponent choose their colour

The game details will tell you what to do - so don't worry!

F(irst)M(ove)P(urchase)


All the other games do have fewer fields, so this opening is not a way, but after some thinking, I came up with another fairness mechanism: the First Move Purchase.

If a game includes a bet, the creator of the game can optionally define what the first move is worth to them and offer that to the potential joiner. If the joining player decides to buy the FMP, they will automatically become the first mover in the game. The price goes 100% to the creator, not to me. I think this is a pretty clean and honest way to balance things 😉

Especially for games with bets, balancing and making these games as fair as possible from the ground up, is super important.




The Smart Contract (High Level)

There is a single smart contract deployed on the Magi chain (this is probably version 5 or so lol). It handles everything:

  • game creation
  • joining games
  • validating moves
  • detecting wins, draws, resigns, and timeouts
  • handling optional bets and payouts
  • sending events for a beta indexer

All moves are validated by the contract itself. No server decides anything. If something breaks, it breaks for everyone equally, but I doubt that it will do. See the unit tests about what was covered with every iteration, and trust me - I have made at least 50 games in different configurations - It was never the contract that broke, and that's the only really important component of all. Everything essential happens directly inside the contract, while the frontend and the beta indexer exist to make things easier to use. If you want to get crazy, you can even play the games with the keychain playground lol

The contract is verified with commit afdbf40 on-chain (see tab "Source Code" of the contract) and linked to my public GitHub repository.




Free, Really Free

Again - just to be super clear:

  • Not a single coin goes into my pockets
  • No fees, no rake, no funny business
  • Everything (including my source code) is free to use

If you want to support me, my wallet will appreciate every little donation!
And if you have smart contract ideas, my Discord is always open for new ideas!




What’s Next

In the next post, I'll talk about another contract I have completely finished already but still needs to get verified:

The multi-DAO contract called Ōkinoko ShinDAO is already live (as [beta].

I didn't want to mix both topics into one post as I'm proud of both projects for very different reasons, and I think each one deserves its own space.




Final Words

The contracts and the website are tested pretty well, especially the smart contract part. Still, if you ever find a bug or something strange, please tell me.

I can’t offer you a bounty...
But you’ll get a very warm thank you in the name of the community ❤️




Happy Gaming!


Sort:  


This post has been shared on Reddit by @x-rain through the HivePosh initiative.

😍😍😍 Thank you @x-rain for sharing <3

🙂 You are welcome. Thank you for this work.

Amazing. Let's try

Yessss 🔥

you could create a notification post container and tag users on the comments instead of sending 0.001 hive... just an idea

hmmmmm that sounds like a very smart plan! Thank you <3

Good gaming. I'll try to keep testing. Any particular test you need?

Haha thank you and congratulations for the win :) You've tested good already - I think it's all fine. Hope you'll have fun with more games and the upcoming contracts ^^

tks. i joined one lottery and will join more as soon as i rechard my magi account

Amazing work!

Thank youuuuu <3

How do we cancel games?

by resigning the game - but only before the first joined the game. from then you will lose the game.

It updates automatically?

yep if you keep the board open - it will update automatically. The numbers on the game type selection ("your turn: 1") are not updated automatically yet tho. this is already implemented but not deployed yet.

It will make a noise when the new move comes in?

ehhm it makes a noise when your transaction was executed. if it does make a noise when a new moves comes in then this is a bug - but a nice bug and I write that down as feature :D

Well, I just came back and checked for a move and it says you made your move 17 minutes ago, that is a little lengthy, imo.
Perhaps if there was a noise to indicate a new move I wouldn't take so long to get back to the game.
I see that refreshing doesn't help.

This is awesome.

I like the fact that you're notified when your opponent makes a move. Kudos to the brains behind this.

Thaank you <3 it is actually one brain - me :D

Such a lovely read. Congratulations 👏🏿.

I am 100 trying the game out
I think I already did but no one else is in the lobby, haha. I was going to ask if I need to be on the app for I love the notifications part

Thank youuuu brother! I joined your two games :) Now you just need to click them to make your first move <3
The notifications where skipped because of not enough RC on Hive for the @okinoko account haha - I delegated some from DIYHub now to okinoko and they should get sent in a few minutes.

Thanks for trying the games out buddy!

Awesome
Where do I click to make my money?

Directly on the "> your turn" row and that will open the game board :) GO GET THAT PENNIES!

Bro you never actually played the game :D

i tried creating a game. not sure if it worked. its showing that i dont have any hive in my stats

Yes the games have been created and I joined them! It's showing Hive from your Magi wallet - you probably have no Hive over there(?)

sorry yeah i guess im confused. what is the Magi? is that the smart contract you created to house different tokens?

Magi is the chain formerly known as VSC. In there, I have created a smart contract for the game (which is not any token contract) :)

Das ist so ziemlich mein gaming Werdegang, nur, dass ich nie ins Programmieren gegangen bin. Mit meiner Tochter spielen wir relativ viel Tic tac toe, der werde ich deine Seite mal zeigen - vier gewinnt ist ja noch mal was anderes, das gut alte Plastik Gestell mit roten und gelben Knöpfen... Vielen Dank für die Arbeit!

Danke für Dein Kommentar! Ja das Plastikgestell von Vier Gewinnt - hab das Klappern noch im Kopf. Sag gern mal bescheid, falls du ein Spiel erstellt hast. Dann können wir auf alte Zeiten eine entspannte Runde spielen :)

i like the retro games to they have no dlc here is a tip for !BBH

Thaaaanks!

Norman, really cool! But…
I tried the App on my iPad (since I had to sign in with HiveAuth per QR Scan with my iphone). Worked. But when signing the „Create Game“ it doesn‘t work. I sign with HiveAuth on my iPhone but the iPad stays frozen. Doesnt start the Game.

Heey yes there are some things that are not very clear yet - most importantly that a signed transaction takes some time. When you create a game and sign the transaction, you will still need to wait for the magi chain to execute your tx. That's not like 3sec - more like 1min block time over there.

Vut even of you wait for 1min - your game will not start because you need to wait for an opponent first. I will add all of these things as info boxes or something so it will become more clear.

For now: I have joined your gaaaames - let us plaaaay :P

Noch recht hakelig. Ok. Denke ich habe jetzt eines der Spielrunden gefunden und mal nen Move gemacht. 😋

Jaaa aber das ist der Natur der smart contracts / Blockausführung geschuldet. Aaaaber: Ich hab jetzt ein Popup eingebaut, dass man nicht mehr versucht das gleiche Game mehrfach anzulegen oder den gleichen Move mehrfach zu senden :D

Update wird dann heute noch in die produktive Umgebung kommen :)

außerdem bin ich deinen beiden games gejoint :) Du bist dran :D

Also wie schaut es aus? Willst du noch spielen oder wolltest Du nur den Games joinen? :D

@borsengelaber @alessandrawhite please check the issues you reported to me - they should be fixed now (and more got optimized in the meantime) :)

I got to thinking about it and I think a troll box would be the ticket.
That way we can see others in the game, too.

Update: @tibfox, I paid out 13.788 HIVE and 1.224 HBD to reward 9 comments in this discussion thread.