Video Week 1 – Snakes & Ladders

Hi everyone!

Hope you are all keeping safe and well, getting lots of exercise and fresh air, doing your work that your teachers have given you and of course helping out around the house.

I’ve made a video of how to make a snakes & ladders game in scratch. It is tailored towards my Explorers Group here in Coderdojo, Athenry but of course it is available to anyone and feel free to share it.

I hope to do more if I can but you’ll get notified when a new video is up. I have created a YouTube channel so you can the video as it was too large for this website.

Here is the link: https://youtu.be/cjQ0qE6ALLI

Hope to see you all soon and don’t forget,

KEEP WASHING THOSE HANDS!

 

Martha

Hackers – Connect 4 Mechanical Design

This week we looked at the mechanical design for our Connect 4 robot. We need a way to hold the tokens and drop one into a slot when the game-playing AI decides what to play.
We started with two ideas for holding the tokens:

  1. A vertical magazine with 21 tokens held in place by two pins.
  2. A disc holding the tokens at the edge.

The photo below shows an illustration of the magazine idea.

magazine3

The magazine would move across the board and drop a token into a slot by pulling out the lower pin. The upper pin would hold the rest of the tokens in place so that the wouldn’t drop into the board. Once the bottom token was dropped, the lower pin would be pushed back and the upper pin pulled out to allow the tokens to drop down one step.

The disc idea involved it rotating into place over the board and dropping a token into the board as needed.

We decided that both ideas were impractical on size grounds: the magazine and disc would be very high and hard to support.

We eventually settled on a modification of the magazine idea: 3 magazines with 7 tokens each. This would be smaller and more stable. It does require us to keep track of the number of tokens in each magazine. That’s something our code should be able to manage.

We decided to keep the position of the magazines fixed. A carrier (think cup) could move under the magazine, collect a token and drop it into the board. The magazine and carrier would both need a single pin at the bottom to hold the tokens in place. The carrier should be the height of a single token, so that only one can drop into it. The carrier would have an arm (like a handle) that sits on the magazine side and holds the other tokens in position.

We spent some time discussing how to move the pins in and out before one ninja had a great idea: the pin should be the arm of a servo motor. The servo can rotate the arm through 90° to allow a token to drop.

We then considered how to move the carrier back and forth. We settled on having a single stepper motor drive a gear on a rack that holds the carrier. Turning the gear moves the rack and the carrier into position. Keeping track of the carrier position might be difficult. The easiest way would be to measure the time it takes to reach a particular slot and then power the motor for that amount of time. The problem with that is that it depends on the motor always taking the same amount of time to reach a slot. The motor might slow down as the battery driving it runs down. Mentor Declan suggested using a beam sensor to locate the correct position. We could put a marker above each board position and stop the motor when the sensor reaches the marker. That marker could be something as simple as a small hole. If the beam shines through the hole instead of reflecting, the mark has been found.

Lastly, we considered how to hold everything in place. We think that a large piece of plywood should do the job. We can also attach a sheet of paper to the plywood behind the board to help the vision system see the empty slots. Mentor Kevin pointed out that anything in the background of the board with the same colour as the tokens could confuse the vision system.

The photo below shows a sketch of the final design.

final_design

So, where will the parts from our design come from?
We have an old flatbed scanner that we can scavenge parts from. It has a gear and rack system to move the scan head. It should be long enough to meet our needs. We haven’t looked at the motor that drives the gear yet. We will have to figure out if we can power it and control it. If not, we have motors from previous projects that we can use. The gear probably won’t fit one of the old motors, so we will have to modify it. Or, we can 3D-print a part that will allow us to fit the gear to the motor. That worked well for us last year when we made axles to allow us fit wheels to the motors we had for our hide and seek robots.
We will have to 3D-print the carrier. It will probably take a few iterations to get something that works. It will need to be the right size to hold only one token, and be shaped to stop tokens from dropping lightly and getting wedged. Some experimentation will be needed. We can 3D-print the magazines as well, or maybe make something from plywood strips and cardboard.
We will also need to make a camera mount for our vision system. The mount will need to sit in front of the board, out of the way of the human player. It will need to be in a fixed position so that it covers the whole board and allows us to reliably identify token positions. This will probably be a mix of a 3D-printed part and plywood.
We will tackle these tasks at our next session.

Explorers Week 5&6 – Pacman

For the last two weeks (with a break for a Red Weather Warning!) we worked on a Pacman type game. We tried to put in all the code we have learned over this year and all the games were brilliant and all so different.

 

We designed our own sprites rather than take them from the library.

 

Here are the notes in PDF CDA-S9-Week_05_Pacman.pdf

Here is a link to the game if you want to check it out. https://scratch.mit.edu/projects/375094277

See you two weeks time, keep yourselves safe and healthy.

Martha

Julie, Ruaidhrí, Iseult and Eoin

Modellers – Week 16

We continued with our tank. In this session we:

  1. Used an array to generate multiple track segments (treads)
  2. Uses a curve modifier to fit these around our curve
  3. Used a negative scale to mirror some objects
  4. Created a simple terrain with a cloud texture and a displace modifier
  5. Generated a procedural texture for generating camouflage

Which was a lot!

Here are the video notes:

The updated tank model can be found here.

Hackers – Programming in Python

CoderDojo-Hackers-IntroToPython

As we plan our AI robot to play Connect-4, we have decided that Python would be a good programming language for the job, as it is widely used for many of the tasks we will need to do:

  • Computer vision
  • Artificial intelligence
  • Hardware control

Therefore, we spent time this week brushing up on Python. Following the same approach that we had used previously to move from Scratch to C, we looked at how we would move from programming in Scratch to Python.

Here is the full set of notes (PDF): CoderDojo-Hackers-IntroToPython

Kevin then spent time explaining how to write a basic Python program to read an image from a webcam. Here is the code:


# We are using OpenCV
import cv2

# Capture webcam image
camera=cv2.VideoCapture(0)
val, img = camera.read()

# Display the image
cv2.imshow("Window display", img)

# Stop using the camera
camera.release

Modellers – Week 15

This week we continued with our tank model.

We created a set of wheels from a cylinder which we then scaled, duplicated and used inset and extrude to provide a little detail on each wheel.

We then created a bezier curve to define the shape of the track across then wheels. Bezier curves are an easy way to defined a smooth shape. They have a number of points through which the curve passes. Each point has a pair of handles. The rotation of these handles defines the angle at which the curve passes through the point. The distance between the handles defines how tightly the curve bends as it approaches the point.

Here are the video instructions for this week:

The updated tank model can be found here.

Explorers Week 4 – Maths Game

Hi everyone,

You all did great work on Saturday, there was some quite complex thinking to be done to figure it out but you did great!

CDA-S5-Challenge_10-Maths game-how to

  1. the player picks a level of difficulty and the computer chooses 2 random numbers to add (subtract or multiply- whichever you choose!) together and show the numbers to the player. Fr this we needed 2 SPRITES and 4 VARIABLES called SCORE, LEVEL, NUMBER1 and NUMBER2 as well as 2 BACKDROPS. CDA-S5-Challenge_10-Maths game-ask questions1CDA-S5-Challenge_10-Maths game-ask questions
  2. The player then has to enter an answer to the equation and the computer tells them whether they are wrong or right. CDA-S5-Challenge_10-Maths game-decisions alternative end
  3. We repeated the ask/answer questions 5 or 10 times. Can you figure out where the REPEAT loop fits?
  4. We also had a second sprite who reacted positively to correct answers BROADCAST and negatively to wrong answers BROADCAST. You can use whatever sprites you like and change their look whatever way you like. One coder added a puppy as their second and had him bark whenever an answer was correct. CDA-S5-Challenge_10-Maths game-sprite 2
  5. After all the questions were asked we had the 1st Sprite SAY – Game Over! and BROADCAST Game over so that the backdrop changed and music played. There are two ways to change the backdrop- see below!CDA-S5-Challenge_10-Maths game-alt backdrop CDA-S5-Challenge_10-Maths game-backdrop

Can you improve our game??! Can you figure out how to subtract or multiply instead of add? Can you get the computer to add three numbers together or give the user 3 level options like: easy, medium or hard? The notes for the Maths Game are here: CDA-S9-Week_4_20-MathsGame.pdf

and here is a link to the game

https://scratch.mit.edu/projects/367754778/embed

See you all in two weeks, enjoy the mid term break!

 

Martha

Julie, Ruaidhrí, Eoin and Iseult

Brainstorming a new Hackers project – an AI robot to play Connect-4

conn4

The Goal

In this session, we started planning how we will build an intelligent robot that can play the game of Connect-4. Our aim is that it will be like playing against a human, with a physical Connect-4 set, not just a computer game. This is the plan we had come up with during our brainstorming the previous week, so this week we started to figure out how we can achieve this.

This will be a challenging project that the whole group will work on together. It will require lots of teamwork, collaboration, and learning.

C4-MainPlans

The Major Components

We spent time thinking about the major components that our system will need, and planning the major tasks for these components on the whiteboard. They will include:

  1. A robot mechanism to play a move, which will involve moving to one of the positions 1-7 at the top of the board and dropping in a token, then reloading for the next time.
  2.  A camera to view the board and analyse what it sees, to figure out which spaces have a red token, which have a yellow token, which are free, and whether anyone has won (4 in a row) or has a promising state (one or more 3-in-a-row).
  3. An AI decision-making system (see below)
  4. A software version of the game that we will find online and modify so that our AI can play it, so that we can work on the AI before the physical robot is ready.

For each component, we identified some major tasks and people volunteered to work on 2 major components each.

We also agreed that Python is a good programming language for the task, so we will have to brush up on Python next.

C4-AI

The Artificial Intelligence

The group spent some time playing rounds of Connect-4 against each other, in order to get us thinking about how we would design a computer strategy to play the game. Then we returned to the whiteboard, where people gave their ideas about the main strategies to be followed – these are on the right side of the whiteboard.

Some of the strategy ideas people proposed:

  • Work towards 4 in a row (obvious but important!)
  • recognise states with the potential for 4 in a row
  • have multiple paths to win
  • try to block your opponent.

This made me think of a general AI algorithm for playing 2-person games, called the Minimax Algorithm. This is based on constructing a game tree of all possible future moves, by yourself and by your opponent, for a number of steps into the future (called the lookahead or depth limit). Then, we evaluate all possible future game states using a utility function (also called fitness function): this will return a low value (e.g. -20) if we lose, a high value (20) if we win, or some other intermediate score if the game is not over, such as a count of the number of 3-in-a-rows we have, minus the count of our opponent’s (this will definitely be between 20 and -20). We will then pick the move that should lead to us a state with as high a utility as possible. Also, if we assume our opponent is rational, they will pick the move that will give us as low a utility as possible, so we can use the game tree to predict what their best possible move is, and be prepared for them! Each time they take a move, we can re-calculate the game tree to plan a new best move.

We then looked at the strategy ideas people had proposed, and saw how they are achieved by the Minimax algorithm, even though it’s a general algorithm, not just for Connect-4!

There are some good videos and tutorials about the minimax algorithm on line. Here are two that I liked:

 

Modellers – Week 14

This week, we finished our apple project started in week 12. We took the images we’d made and stencil painted them onto our apple model.

Here are the video instructions for the stencil painting:

The completed apple model can be found here.

Once we finished the apple, we started to talk about animation. To illustrate this, we started building a little multi-object tank model that we can later animate. Here are the instructions on starting the tank model:

The in-progress tank model can be found here.

Modellers – Week 13

This week we had a 3D printer in the room, so our plans to stencil paint the apple took a back seat until next week. Instead we printed a dice model and then looked at how to build that model.

The printer we used is a Prusa i3 Mk 2.5. To print a model you import it into a program called a slicer which converts it from a polygon based model into instructions for the printer in how to lay down a series of layers of plastic to build the same approximate shape.

The model we printed was a dice. To do this we used ‘hard surface modelling’ techniques, specifically the use of boolean operators. Boolean operators allow you to take two shapes and make a composite shape that is:

  1. Difference: The first shape with the second cut-out
  2. Union: A shape which is the two shape fused together
  3. Intersect: A shape which is only where the two original shapes overlapped

This technique is powerful, but it results in many N-gons (polygons with more than four sides). N-gons are bad in many circumstances. For example severe distortion may result if :

  1. If we try to apply smooth shading
  2. If we try to apply a subsurface modifier
  3. We later try to distort the mesh, as with an animation
  4. If we export the model for use in other 3D packages

If none of those apply, hard surface modelling can have its uses.

Here is the instruction video for this week:

The dice model file can be found here.