My First Semester at University

Overall I have really enjoyed my first semester at Coventry University and feel that I have done really well in the past three months. This semester I studied three modules: Introduction to Computing, Logic and Sets, and Enterprise Information Systems.

For Introduction to Computing, I achieved 85% in my first phase test and 100% in the second one. My coursework grade and exam grade make up the rest of the module but I am still waiting for both of these results back. I think this was my favourite module so far because it is the one I did best in, and because it all involved programming and this is one of my favourite parts of computing.

Logic and Sets is made up of two coursework assignments. In the first I got 100% and the next one is to be submitted at the end of the semester so I haven’t yet got any feedback for it.

In Enterprise Information Systems, I achieved 90% in my first phase test and 65% in the second phase test. I am slightly disappointed that I didn’t get 70% or over in the second test as this would have meant I got a first in everything so far at this point, but it is still a good grade. I am still waiting for my coursework grade back and take my exam for this module in a few weeks.

Overall I think I have achieved good grades throughout the course so far and I am fairly confident I will get good grades in my upcoming exams and coursework at the end of the semester.

Programming Coursework Project

My programming module in my first semester requires me to write a programme to play the game Noughts and Crosses.

The games requires:

  • Displaying the grid which updates after each turn
  • A check for when the game is complete (won or drawn)
  • Option to play again after the game has finished
  • Option to play against the computer or against another human player
  • Artificial intelligence for how the computer takes its turn instead of just making random moves
  • Ability to save the game mid-way through for completion later
  • Documentation, instructions to the user, comments in my programme to explain the code, and use of docstrings.

When first starting this project, I began by planning out how the game of Noughts and Crosses is played normally, and broke down into stages the different parts, and functions required for the game. From this I could think of it from a programming point of view and set out what processes and functions I will need to develop.

To do this I first put comments for each section and sub-section of my code and ordered them in the order I thought they would need to be in. I like to do this when starting a project because it helps to set out what I am going to have to do; instead of just diving straight into coding, I feel that good planning helps a lot. Obviously I cannot plan everything and when I started coding I soon found that I had to rearrange the order, or maybe add in more sections than I initially thought were needed, but this is a normal process when programming and I still found that it helped a lot to set out the foundations of my programme. This process also allows me to set out the requirements for the game and allows me to meet the minimum requirements for the game before moving onto other sections.

One way to help me plan and organise this project was using a flow chart to illustrate the structure of my programme. Below is a copy of the final version, but this was updated and edited throughout the development process until I got it to a stage I was happy with:

Assignment Flow Chart PNG

One of the main features the game must include is for the game’s grid to be updated after every move and displayed to the player. For this I could have just printed out the grid after each turn, but instead I chose to use Python’s turtle function. Turtle is a feature of Python which allows you to draw lines and shapes in a window, so is an ideal representation of when you draw the noughts and crosses if you were playing the game on paper. This also meant that I didn’t have to keep showing the grid multiple times, as the grid would just update and is always in the same window. This is a feature of my game I was really pleased with, and I am glad I made sure to include this as it makes it look higher quality and more professional; as well as being easier for the user to see what is going on. This was something which helped improve my game, so I didn’t include this until the basic functionality of the game was done first, and then I could focus on using turtle and making a graphical version of the game.

To check if the game had been completed (won or drawn), I used a global list variable to represent the grid squares. This list is what is updated throughout the game and is the key part of the programme. Every time the player makes a move, a function is called to check this list. This checks to see whether there is a winning scenario depending on the values in the list, or if the list is full with no winning scenario then it is a draw.

These features I have so far discussed are all for when playing versus another human player; however, one of the main aspects of the game is playing against the computer. After I created a multiplayer game that I was happy with, I started developing a version where you play against the computer. To include this, the game now includes an option for the user to choose if they want to play multiplayer or versus the computer.

When playing versus the computer, the computer cannot just be making its turn at random and so there needs to be some sort of artificial intelligence in the decision making of how the computer picks its turn. I have created a separate blog post detailing how this was implemented here.

One of the last features I included in my game was the option to save the game and complete it later. To do this I used Python’s pickle feature to save and load to a text file. I saved the grid squares list to the file and from reading this the game could load up to the same point it was at and then continue the game. One problem for this was that because I was using turtle, it meant adding a loop to redraw all of the already existing symbols again, but after this is done the game can continue as normal. One issue I had was implementing the save/load feature for the game versus the computer. I was saving the list to the file and there was no way of loading this data to find out which game mode had been selected. Therefore, I decided to create a global variable for the game mode that was selected and pickle this variable as well so that it could load this and know which type of game was saved.

Throughout my programme I have made sure that it is documented using comments and docstrings. This has meant it is really easy to see what is going on through my programme and when errors have occurred it meant that I could easily identify what went wrong. For all of my functions I have made docstrings which sets out what each function does step by step, and which function call or output is returned from the function. Also for some areas in the code it has been useful to have short descriptions in comments of what the variables, if statements, and loops are actually doing.

Overall I am very happy with my programme and think I have achieved what I set out to do. However, I feel that I could have gone one step further with my programme to improve it. I was considering have a feature where the user can point and click on the grid squares to make their move, instead of entering a number corresponding to the grid square. This would have been a great feature to have because it would have meant not needing to explain to the user which number represent which grid square. However, this would have taken more time than what was needed and doesn’t offer any further functionality to the game, so I decided to leave this out.

Artificial Intelligence in Noughts and Crosses

One of the main features of my first semester’s game was to include some sort of artificial intelligence when playing the noughts and crosses game against the computer.

When thinking about this I decided to split this into two different sections, early game and end game. Early game is the first move of the game where the computer decides its move to give it the best advantage of winning. End game is where the computer has to make its move to block the human from winning, or make its move to win the game.

There are 8 possible winning scenarios in noughts and crosses, so when the computer is making its move it should be doing so, so that it can win in as many scenarios as possible. Therefore, in the early game I want it to make its move where it is giving itself the best chance of getting three in a row. For example, say the player has gone first and chose the top-left square in the grid. If the computer was to choose a square next to it in the same row or column as the player, then they are limiting themselves to just one possible winning scenario, whereas the middle square would give the computer three possible winning scenarios at this point in the game. So my artificial intelligence needs to tell the computer to check what will give it the best chance of winning, based on the already existing move.

Here is an example of what the computer should be deciding for its move:

Artificial Intelligence Diagram 1 PNG

After the first move has been made by the human player, there are 3 general rules that the computer is taught to play:

  1. If the human plays a corner square, play in the middle square
  2. If the human plays the middle square, play in a corner square
  3. If the human plays a side square, choose the middle square or the corner squares furthest away from the already chosen square

Artificial Intelligence Diagram 4 PNG

To implement this I first did a check when the computer makes its turn to make sure that it is the first turn. If there are 8 possible moves for it to choose from, then it must be the computer’s first turn. Then I do a check for each of the 9 squares to see which one the human player played in, and depending on which square has already been played I then narrow down the possible moves to just the ones it should be playing. So before this there were 8 possible moves, but after it has checked where has been played, the list of possible moves will now be either 1, 3, or 4 grid positions (depending on the scenario). After it has determined a new list of possible moves that it should be considering, it then carries on to choose a random selection of these possible moves.

The more important part of the artificial intelligence in my game is what happens in the end game. The first check should be if the computer can win the game, and the computer needs to be able to know when it is one move away from this and to pick the square that will win the game. As well as this, when you play noughts and crosses normally, you must always look to stop your opponent from winning if they are one move away from doing so. Therefore, I need an initial check by the computer to analyse the state of the game so that it knows that the first thing it needs to do is try to win the game and if it can’t do this then stop the opponent from winning.

Here is an example of what the computer should be doing when it is one move from winning the game:

Artificial Intelligence Diagram 3 PNG

Here is an example of what the computer should be doing when the human player is one move from winning the game:

Artificial Intelligence Diagram 2 PNG

To implement this I used two checks, first check if it must play a certain grid square to win, then check if it must play a certain grid square to block the opponent from winning. For each of the 9 grid squares I checked all of the scenarios where that square will fill in a 3 in a row scenario, and therefore must pick this square. If this is the case then the computer will pick that square, otherwise it will keep checking the others. If it doesn’t meet a scenario where picking a certain square wins the game, then it will do a similar check to block the opponent. The only difference in this check is that it is checking the opponent’s moves instead. If it doesn’t meet a scenario in this check, then it means it doesn’t have to pick a specific square to play in, and the computer is allowed to choose any random square from the possible moves list.

 

Objectives for my time at University

My main objective whilst at university is to achieve a first honours degree in Computer Science from Coventry University. This is my primary goal for the next three years and it is important that I aim as high as possible in terms of the grade I will get when I graduate. Gaining a degree isn’t always the normal route for people to take these days, and I have considered alternative routes in the past, but I believe now that achieving a degree will give me a great start to my career and set the foundation for success. This is my main goal whilst at university, but there are other aspects of university that are important for me to consider as well.

Whilst studying at Coventry University I want to gain experience and knowledge that I can take into my career. This is important for me so that I can demonstrate the skill set that employers are looking for after I graduate. Employers want to know that I am a capable individual that has the skills required for their roles, and that they don’t need additional training because I will already have the experience and knowledge from my time at university.

It is also important for me to take advantage of the opportunities available to me whilst I am studying and possibly work in projects that become available for students to participate in. There may be opportunities for me that I won’t get the chance to do again so  whilst at university there will be lots of projects like this and it is a great time for me to do things like this to build a portfolio and show to employers when I start applying for jobs.

Another part of my university life is the experience of meeting lots of different people from many different countries and different backgrounds. Coventry University has students from over 150 countries, and I am already meeting people from various different pathways