Building a Tic-Tac-Toe Terminal Game using Python
Tags: beginners, python, ai, learning
Published: 2024-07-11 23:06:17

## Introduction

My name's Derek and I'm an aspiring software engineer! Recently I've been trying very hard to learn Python and the fundamentals of software development through an online course. Having graduated from college two years ago with a Bachelor's in Business Computing and Information Systems, I am relatively familiar with the software development process and have some IT skills; but I have quite a bit to learn on the technical side when it comes to programming and problem solving. So, I decided to take the aforementioned course as a means of supplementing the knowledge and skills I was able to pick up while in college and making my resume stand out more. Since practice makes perfect, especialy in the realm of IT, I decided to undertake a project in support of the programming fundamentals I've been learning in the course. And for this project I decided to build a tic-tac-toe terminal game: something that would be fun yet challenging to do. I am writing this post to share the finished product I was able to conjure up (with some help) and get some feedback on my execution of the project along with how best to proceed with my journey of becoming a software engineer. So let's dive right in! 

## A Description About the Code

The way that the program was built was by breaking down the overall solution into a number of smaller components called functions that all work together to form a working application. The first function was the _**insertLetter**_ function, which is what allows the player to place a letter onto the board. The second function was the _**spaceIsFree**_ function, which checks whether a space is free before an insert is made into that spot. The third function was _**printBoard**_, which draws the tic-tac-toe board and updates the board with moves made by the player and the computer. The fourth function was the _**isWinner**_ function, which keeps track of the moves being made on the board to then determine whether the player or the computer is the winner. The fifth function was the _**playerMove**_ function, which allows the player to make their move on the board. The sixth function was the _**compMove**_ function, which allows an ai opponent (i.e. the computer) to make moves with the core aim of winning the game. The seventh function was _**selectRandom**_, which enables the opponent to make moves at random that could potentially lead to a win. The eighth function was _**isBoardFull**_, which checks to see if the board has been filled with moves and if there are no more empty spaces so the game can be brought to an end. The ninth function was _**resetBoard**_, which clears the board should a player want to play another game of tic-tac-toe. The final function was _**main**_, the function that makes use of nearly all the other functions in order to allow a game of tic-tac-toe to be played.

To review the code for yourself or to be able to play the program for yourself, here's a link to the GitHub repository for the Tic-Tac-Toe game: [Tic-Tac-Toe Terminal Game](https://github.com/Keelan-Derek/Tic-Tac-Toe). 

## Conclusion

While this project was a bit challenging, the making of this application taught me a lot about what goes into building an application: I had to think of an idea, understand the problem at hand and break it down into solution components, control different versions of the application while building the actual application, troubleshoot bugs and errors, and maintain the applicaiton so that it worked efficiently and effectively post development. That said, I have much more to learn and a lot more practical experience to gain as a junior software engineer. If anyone of you so happens to be interested in mentoring me, offering me a paid internship position, or giving me advice, I'd be more than grateful. Have a nice one and hope you enjoyed this amateur blog post.