For my
final blog post I am going to talk about computer science. To help me explain such a broad topic, I am
going to use a program I wrote a few months ago that simulates a game of
checkers when you run it and, due to a limited amount of space, I can only briefly
talk about the concepts behind this program. Since Computer Science and the
program I'm using as an example are both very complex topics, I'm going to
primarily focus on the way a computer thinks when it compiles code. Before I
can go on to explain checkers, I would like to talk about how computers think
and function very briefly. A computer can't look at a situation and assess it
like we can as humans. A computer can
only recognize two things: whether a condition is true or false. To best show
what this means, you can look at binary. Our number system is called
decimal. It has ten digits and is easy
for us to understand because we can count to 10 on our fingers and it's a
fairly simple system. Binary is different in the sense that it only has two
digits--0 and 1, 1 being true and 0 being false. At the end of this post I've
linked a video that explains how to convert from decimal to binary for those
who are interested in the topic.
Since a computer can only recognize things as
true or false, you have to keep this in
mind when you construct the game board. To do this, I used something called a
two-dimensional array or a matrix. A matrix is like a grid where it has two
values (an x and a y) and it uses those two values to find the place in the
matrix you're looking for, then it returns that information. I've posted a picture of the matrix bellow.
As you can see, there are four different values on the board: an X which represents the spaces you can't "jump" your pieces to, an empty space which represents the empty places on the board, a capital O which represents one player's pieces, and a lowercase o which represents the other player's pieces. Now that I have a board created, the next step I had to take in writing my program was taking this matrix and making a visual representation of it as a game board. To do this, I used text and something called a loop. A loop is a type of function that will repeat itself until its condition is false.
Unfortunately due to a lack of space I could only briefly
describe to concepts of this program. Other parts of this program include:
selecting a piece to move, returning move options for the selected piece,
identifying when a player can jump another piece, identifying the possibility
of multiple jumps, and also implementing the king piece.
https://www.youtube.com/watch?v=Q2UgMYwWiO4 - David
Williams: Base 10 to Base 2 (Decimal to Binary) Conversion