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.

Explorers Week 3 – Storytelling

We had a great day in Scratch Beginners on Saturday! We created a project in which the Sprites communicated with each other to tell some sort of a story or bad joke, Like I did!

 

Timing was very important, each sprite had to wait for the other sprite to have their say.

Here are the notes from this week CDA-S9-Week-3-StoryTelling.pdf

 

We are going to do a great Maths Game this Saturday so we look forward to seeing all there.

Martha

Ruaidhri, Julie, Iseult and Eoin

Modellers – Week 12

This week we looked at colour and generating textures.

White light contains all other colours; we can see this when a prism splits it into a rainbow. A green object appears green because it absorbs other colors and bounces the green light back and into our eyes.

When we render an object in Blender, or any other 3D software, we want the renderer to generate the highlights (specular reflections) and shadow on the object. Any texture we use should be as free of highlights and shadow as possible.

To generate a relatively highlight and shadow-free texture of an apple, we used a pop-up portable photo studio. The interior of this box is white and reflective and lights the object relatively evenly on all sides.

IMG_0725

We photographed the object, an apple in this case, at four angles around the circumference and once again for the top and bottom of the apple respectively. This left us with six shots of the apple from all sides.

combined.jpg

I then opened each shot in Gimp (the image editing software), and removed as much of the rest of the image, everything that wasn’t apple, as possible. To do this I:

  1. Used the Rectangle Selection Tool to select a box close in around the apple and then used Image | Crop to Selection to remove the rest of the image
  2. Used the Fuzzy Selection Tool (aka. Magic Wand tool) to select white areas. I adjusted the Threshold value in the Tool Options panel as high as possible so that no parts of the apple were being selected when I clicked. I then used Edit | Cut to remove those portions.
  3. Finally, there were portions of the supporting bowl that were still remaining. I used the  Free Select Tool (aka. Lasso Tool) to select these and remove them.

Once I had each photo of the apple cleaned up, I created a new image, and pasted all the individual images into it, scaling them so that they were close to the same size. The result is here:

apple.png

We also built a simple apple model by shaping a UV sphere. Next week we are going to stencil paint the apple model with this texture.

The apple model can be found here.

Explorers Week 2 Breakout!

Hi everyone

This week we finished our game from last week, Breakout!

Now there were a lot of complex ideas, rotations, degrees and we created two variables.

Here are the notes in PDF from CDA-S8_Week 1_20-Breakout.pdf

If you want to upload your own game, log in with the following details on http://www.scratch.mit.edu

Username: cdathenry1920

PSW athenry1920

Here is a link to the finished game that I have uploaded to the scratch website

https://scratch.mit.edu/projects/362453265

 

Modellers – Week 11

Hi Folks. Minimal notes this week as we spent the session working with the sculpting tools in Blender; something you really just need to try for yourself.

To start a new sculpting session, just choose File > New > Sculpting to be presented with a  high-resolution quad sphere and an array of sculpting tools.

Of these tools there are three I find most useful:

  1. Draw: Normally pulls out the mesh, but will create depressions when CTRL is held
  2. Crease: Makes fine creases in the mesh. Great for adding detail
  3. Smooth: Great for when the mesh has become a little rough or uneven

You should experiment with the others to see which you like best!

Finally, here’s a little rough and unflattering 10min self-portrait I knocked up at the end of the session, just for laughs:

sculpt

When sculpting, it a good idea to remesh from time-to-time where you’ve significantly deformed the mesh. Remeshing evens the mesh spacing automatically, avoiding places where individual polygons are overstretched, but it’s only available in Blender 2.81. Some people had this version already installed, while others installed it during the session. If you haven’t got it yet and would like to install it you can get it here.

Finally, here’s little personal project you might like to see. I sculpted and painted my cat Noodle’s head. I used a couple of reference photos and a technique called stencil painting to generate the texture:

 

Hackers – Components of a Desktop PC and a Raspberry Pi

pc+pi

At CoderDojo Athenry, the Hackers spent some time examining the components of a desktop PC and a Raspberry Pi 3+ and a Raspberry Pi Zero.

Even though the Pis are much smaller than a desktop PC, they are functionally equivalent – as we saw, you can plug the Pi into the keyboard, mouse and screen of the desktop PC and use it like one.

We identified the major components of a desktop PC, and saw where each of them appear on the Raspberry Pi also:

  • CPU – the central processing unit that does all calculations and processing. All data in a PC gets represented as numbers, so all data processing ends up as calculations.
  • GPU – a dedicated processing unit just for graphics, that specialises in multiplying and adding matrices (pixels on a screen are represented as a matrix). Not all PCs have one, but they are important for high-performance graphics.
  • RAM – the short-term memory of the computer, used by the CPU to store data.
  • Hard Drive – this might be a hard disk drive or a solid-state drive. This is for long-term storage. It holds much more than RAM and the data remains when the PC is powered off, but it is much slower for the CPU to get data from the hard drive than from RAM.
  • DVD Drive – not all PCs have this. DVDs or CDs allow permanent storage that can be removed. Some are read-only and some allow reading and writing.
  • Motherboard – the circuit board on which everything else is mounted.
  • Power Supply – this is built into a desktop PC. For a Pi, this is a 5-volt supply such as a phone charger.
  • Networking – ethernet for wired networks and/or wifi for wireless networks.
  • Controller chips and connection ports (such USB and HDMI) for peripherals.
  • Case – Pis don’t always have these.

We noted that the Pi has a single chip that has its CPU, a basic GPU and up to 1GB of RAM all stacked in layers on top of each other. While its CPU is lower power than a standard PC CPU, it benefits from having a really short distance that data has to travel from RAM to CPU. CPUs run so fast that having electrons travel a few centimetres is a significant delay!

PCs and the Pi also have connections for peripherals, which is anything that can be connected to it, using USB, Bluetooth, HDMI, or other connection types:

  • Keyboard and mouse
  • Screen

The Raspberry Pi Zero has micro-USB and micro-HDMI connectors to keep everything as small as possible, and it has wifi only, no ethernet port (though it is possible to get a micro-USB to ethernet adapter).

A couple of members of the group have built their own desktop PCs, which is an impressive feat!

Explorers Week 11 Christmas Scene

Thank you so much to Eoin you led the session on Saturday, I think you all enjoyed it. I think you will agree that our two Black Belt Mentors did really well leading their first session. So thank you Ruaidhrí and Eoin

Eoin did a Christmas Scene with you. Here a some screenshots of the code.

See you all on Saturday and Remember bring your own drinks!

Martha

Iseult, Julie, Ruaidhrí and Eoin