npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tribot

v0.0.2

Published

Control a triangular robot, or "Tribot", to retrieve some treasure. Designed for teaching programming, allowing you to use real JavaScript with zero setup and as little boilerplate as possible.

Downloads

6

Readme

Tribot

Control a triangular robot, or "Tribot", to retrieve some treasure. Designed for teaching programming, allowing you to use real JavaScript with zero setup and as little boilerplate as possible.

Getting started

Create a file named index.html on your computer with the following contents:

<script type="module" src="https://unpkg.com/tribot"></script>
<script type="module">
// Your code goes here
</script>

Then open this file in your favourite modern browser (relatively up-to-date version of Chrome, FireFox, Safari, Edge, etc).

You should see this:

Now you can start programming! In index.html, replace // Youre code goes here with the following:

moveForward()
turnRight()
moveForward()

Now save the file, and refresh your browser. Click the "Start" button and watch the Tribot move.

Try editing the code to help the Tribot reach the treasure!

Controlling the Tribot

The following functions are available to control the robot:

  • moveForward()
  • moveBackward()
  • turnLeft()
  • turnRight()
  • changeColor(color): you can use a named color, eg changeColor('blue') or a hex color eg changeColor('#800080')
  • beep()

Change the room

There are 3 preset rooms. By default room 1 is selected. You can instead try putting the Tribot in another room by calling setRoom(roomNumber) at the top of your script. For example,

<script type="module" src="https://unpkg.com/tribot"></script>
<script type="module">
setRoom(2)

moveForward()
turnLeft()
beep()
</script>

You can also make your own custom room, for example:

setRoom([
  [S,_,_,_],
  [W,_,_,W],
  [T,_,_,W]
])

Rooms have:

  • S: A start position for the Tribot.
  • _: Empty spaces
  • W: Walls
  • T: Treasure

A Simple AI Tribot

Instead of manually giving the Tribot instructions for how to get to the treasure, you may want to try programming a Tribot that can complete any room without a change of code! To help with this, there are a few global variables available to use:

  • gameInProgress: Boolean - recommend creating a loop with this variable as shown below
  • obstacleAhead: Boolean - true if an obstacle (wall or the edge of the room) is in front of the Tribot
  • obstacleBehind: Boolean - true if an obstacle (wall or the edge of the room) is behind the Tribot

Here is a simple example of an AI Tribot! It may succeed in some rooms but fail in others - how could you improve it?

<script type="module" src="https://unpkg.com/tribot"></script>
<script type="module">
setRoom(2)
while(gameInProgress) {
  while (obstacleAhead) {
    turnLeft()
  }
  moveForward()
}
</script>