1. John McDonald
  2. Like Clockwork

Wiki

Clone wiki

Like Clockwork / Home

Like Clockwork

Program your medieval archer bot to seek and destroy your opponents' bots.

* Chrome users must go to chrome://flags and Enable Experimental JavaScript

How to Create a Bot:

Blockly is used to create all bot scripts. They have a wonderful tutorial on how to use it to get through a maze.

From the bot list, you need to log in using either your Google account (or OAuth provider, experimental). Once logged in, click Create a Bot! from the bot list. Enter a name and description for the bot, you will not be able to publish with both of these.

Drag and connect blocks from the sidebar inside the Blockly window to make a script. All blocks must be connected. The entire code block is wrapped in a while(true), so you do not need to manually create a forever loop.

Bot scripts run on "ticks". Right now, each tick is tied to 1 frame. The more ticks your bot uses to do actions, the slower it will be. But, you need to use ticks in order to win.

Here's a quick look at what you can do:

Movement

Moving costs 10 'ticks'. You can move forward or backward. If you bump into a wall, the Bumped flag will be true, but you will still lose your 10 ticks.

Turning left and right consumes 10 ticks, and turns your character left or right.

Use Facing to tell which direction you are facing. Compare this to direction block, or just use the Is Facing block if you prefer. No ticks.

Scan

All scans use 3 ticks and populate the Last Scan Result block that you can compare to the Scan Type block to see what you've scanned (Nothing, Wall, Bot, or Arrow). Scanning left or right will only scan 10 tiles, while scanning forward will scan until it hits something. (There's also a perimeter scan that I forgot to include)

Attacking

Your bots are archers with a limited quiver of 30 arrows. Shooting an arrow will cost you 10 ticks, and 1 arrow. Arrows travel at one tile per click, so it is (barely) possible to scan one and jump out of the way if you're not facing it. Arrows kill instantly (I may change this later).

If you're desperate, you can also stab your opponent, which kills any bot in the space directly in front of you. This will only cost you 5 ticks.

Fight!

From the bot selection screen, select one or more bots (up to 8), then press Fight Selected Bots. You will be taken to the battle ground (assuming you are actually running FireFox 25+). From here, the bots should start following their scripts and try to kill each other, trying ever so hard to be the one and only. If the battle goes well, you will be presented with a screen indicating the victor. You can press any key to replay the match.

Technology Stack

  • Crafty JS - For the battle ground
  • Blockly - For the block programming to JavaScript
  • PHP and MySQL back end

I also make use of a "future" JavaScript function yield, and was able to get this to work in Firefox with no issues, and in Chrome if you enable Experimental JavaScript under chrome://flags.

All of the tools (except JavaScript) used for this were new to me when I started this project.

Bugs

  • More than 8 bots in a battle will cause the battle engine to halt
  • Creating infinite recursion inside your bot will result in more and more yields until the client finally freezes the browser

There are surely some bugs in there. My first tester was able to halt the battle simulation, so surely there will be others. The most common symptom is that the battle simulation will either stop in its tracks, partially load, or not load at all. If any of these happen, I'd like to know which bot(s) cause this.

Wishlist

  • Scoreboard. Record a bot's wins and losses
  • More maps and a map editor where players can make and share maps just like you can share bots
  • Warrior and Wizard classes
  • Mines, Burst arrow shots, more scan types, a block stance, etc.

Creative Commons

Like Clockwork is licensed under a Creative Commons Attribution 4.0 International License.

Updated