Thursday, November 19, 2015

Computer Science and Checkers

                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.
















     The image above is a picture of the two loops I used. While it may look complicated at first glance, when you break it down it is relatively easy to understand.  First, I needed to create two integer values, which are values that can only be whole numbers.  I named them count and countTwo. Then to make it easy to understand the grid and select pieces I include the line System.out.println("      0.   1.   2.   3.   4.   .5   .6   7.").  The function of this is that it prints out whatever is inside of the quotation marks so, in this case it is  0.-7.. The next line says while(count<8). This line creates the loop that I mentioned earlier.  What it is saying is that it is going to re-run the lines of code inside of its curly brackets until count is no longer less than 8, or in other words, until the condition is false. The next line is another print line; however, the only difference between this one and the previous one is that it says print instead of println. What this difference does is that the println automatically creates a new line after it prints out its statement and the one that only says print does not. The next line is another loop that will run until countTwo is no longer less than 8. Then inside of that loop is another print statement that prints (board[count][countTwo ] + " | "). This print statement is going to grab the value at board[count][countTwo] which is like a co-ordinate plane at the point (x,y). It then separates that with a line from the next value it prints. The second loop also contains the line countTwo++ which adds 1 to countTwo.  The first time it runs, it will grab the value from board[0][0] which is X. Then  the second loop will run again printing out the value of board[0][1] which is an o. It repeats this process 8 times.  Then because countTwo is no longer less than 8, it leaves the second loop. The next couple of lines are count++ and countTwo=0.  Count++ adds one on to count, countTwo = 0 resets countTwo so that it no longer equals 8 but 0 again. Then the first loop repeats. Since countTwo was reset to equal 0, the second loop also repeats again, going through another 8 times.  This time it is printing out the values at board[1][CountTwo] instead of board[0][countTwo]. The entire process repeats until count equals 8 and it prints out the entire board, which ends up looking like the following picture. 
 









     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

12 comments:

  1. I think Alex's topic is one that is interesting and a good read since he seems to have a liking/passion for the topic. Having used his own program, it was easier for him to explain and thus made it easier for us as readers to grasp the concept. As a person who knows nothing about how computers work, this topic was still a bit confusing. The binary code sounded familiar and how computers use this code to create determine whether something is either true or false. I liked Alex's idea of running a checkers game through his program. It is an interesting game to look at and to see how a computer program looks at the game. The way a computer and a human look at a game like checkers is completely different. Human's think ahead, have a strategy and a way they like to play. A computer, as Alex mentioned, can only determine true or false. I enjoyed reading about Alex's topic and it was intriguing reading about a topic he is invested in. The only wish I have is that I understood computers better to get a better gist of all the little facts Alex included in his post. I think this knowledge would be useful not only for thus post, but in general life.

    ReplyDelete
  2. I would like to start off by noting how impressed I am that you wrote your own computer program; the topic you chose to write over is obviously a huge interest for you. As for the explanation for the program, I am a little confused, but I know very little about computers and how they work. I also got lost while you were relating the program to checkers, but I have played online checkers before and I’d imagine your program is similar to the algorithm the websites use to play the games. I think this idea is so neat and fun especially because of your level of interest in it.

    ReplyDelete
  3. I think it is super cool that Alex seems to have taken a liking to writing computer programs. It is really impressive mainly because I have seen two of his programs and neither make much sense to me, but he seems quite passionate about them. I also find it interesting that he can create a checkers simulation on the computer. Like I said earlier I do not really understand computer programming and due to limited space he obviously could not go into great detail, but creating a “robot” opponent so to speak is very interesting. All in all, Alex did a great job.

    ReplyDelete
  4. Just by reading this, it’s clear that Alex has a passion for programing. It is impressive that just in one class he could write a program that works and it is impressive how easy he makes it look. With that being said, I know nothing about that type of stuff and the subject is rather confusing for me as a whole. I’m sure to someone who understands computers and programs that this would be clear to them but sadly not to me. Alex did a good job of explaining the step by step process that he created I just cant get a grasp on the whole thing.

    ReplyDelete
  5. Just by reading this, it’s clear that Alex has a passion for programing. It is impressive that just in one class he could write a program that works and it is impressive how easy he makes it look. With that being said, I know nothing about that type of stuff and the subject is rather confusing for me as a whole. I’m sure to someone who understands computers and programs that this would be clear to them but sadly not to me. Alex did a good job of explaining the step by step process that he created I just cant get a grasp on the whole thing.

    ReplyDelete
  6. I think it is impressive and simply awesome that Alex was able to create a program like this and the knowledge behind doing this is very interesting to me. This blog post was very interesting and I am still clueless on how Alex was able to create a program like this, it seems a lot more challenging than he made it seem. I wish I understood computer programming a lot more than I do because this post would make even more sense to me if I could grasp this concept a bit better. This would be something I would like to research and learn more about.

    ReplyDelete
  7. This must have taken a lot of dedication to learn computer science and then apply it to make your own codes. I was very impressed by what you accomplished when showing us in class. It feels like you have to learn an entirely different language. As I read through your post, it didn't seem as confusing as it first appeared. You did a great job breaking down the coding and explaining the parts. I’ve always had an interest in computer science, but always thought it would be too difficult or advanced for me. After reading this post, maybe I’ll look into some basic computer science after finals!

    ReplyDelete
  8. I can tell from this post that Alex really has a passion and a knack for coding. I, on the other hand, I am the exact opposite. This resulted in me being pretty confused as I read Alex’s post. This being so, I did my best to push through. It was hard, but it was very interesting. I think it is amazing how far we have come with technology, both creating it, and applying it to things that help society. I also think it is interesting that all the functions of a computer can be communicated to it with just the use of two numbers.

    ReplyDelete
  9. I’ve always been interested in computer science and writing code for programs I’ve just never put in the time or effort into the field. In high school I took a web design class which I know is very different than writing a code for a working game of checkers, but still has many of the same elements. Alex did a good job explaining how his program works and it really got me interested in maybe getting back into the computer science field. What makes this post so cool is this code was all written and made by him, I find that really inspiring and cool.

    ReplyDelete
  10. It's so amazing how you can dissect and determine call of this coding and programming! I think you did a great job of explaining your processes and how the game works with code, although, being a non-analytical / quantitative-brained person, I still found it a bit difficult to follow (which is not your fault at all - it's not you, it's me). It's really great that you have such a passion and talent for coding and computer science because it's surely going to be a very important thing to be good at in the approaching years of technological advancements! I agree with Vito about the inspiring part - it's very inspirational to see someone my age create such a seemingly complicated program out of just numbers and commands.

    ReplyDelete
  11. I am terrible at computers and usually just play around with things until I get the outcome that I want. The fact that you took time and effort to write your own program is pretty cool, especially because I couldn’t do it myself. I enjoyed that you broke down the program into the simplest way because I know nothing about computer programming. Likewise, the more times I read the post I found it easier to comprehend and understand a little about the program itself. I found it amazing that humans and computers have two completely different ways of thinking about a simple game like checkers.

    ReplyDelete
  12. I think since he used something that he made he did a better job explaining this than anybody could have. I haven't been big into computers, but have been getting more and more involved into them since arriving to college. I thought this was a very interesting read since I know so little about computers and how they function. Since the field of technology is continuously changing this would be a very good field to get into and it seems like he has a passion for it and that is good. There will always be jobs involving this kind of thing that only certain people will be able to do. For how vaguely he was able to describe is program do to lack of space I am glad that it wasn't in full depth because this concept was hard to understand let alone the whole program and the details on how it works.

    ReplyDelete

Note: Only a member of this blog may post a comment.