Simpossible Personality

Hey all!

It’s my birthday! Therefore, I gave myself some time to work on my passion projects, such as this game, and even explore some old design documents which i’ll probably post about a little later today as well!

So a couple weeks ago I shared with you guys my game Simpossible in this post. Since the, I’ve been working pretty hard in school and all that, but I have had some time to work a little more on my game, and wanted to post to further include my audience on what makes this project really special to me!

The personality I’m trying to give this game is what I feel will make it more than just another text based game. I’m doing this in 2 main ways: Words of Wisdom and Words of Disappointment.

My Words of Wisdom are quirky little snippits that are included at the start of every new game, every upping in difficulty, and every correct answer, and  I hope to make them numerous enough that a player never sees the same one twice. They range from dumb little sayings and goofy interactions to actual advice and fun facts.

My Words of Disappointment are essentially the opposite. They’re dumb little snips of the “character” poking fun at, and antagonizing the player, in a very very softhearted fashion.

A great (and incredibly relevant) example of this approach being used is the new game Smash Brothers: Ultimate. In loading screens, tips, backgrounds, and simply entertaining text tidbits appear. They used the text to input personality into the game. My favorite example, pulling from my favorite game, is their background on Sheik. It goes something like: “Sheik is originally from The Legend of Zelda Ocarina of Time, released in 1996. Though her true identity is a mystery at the beginning, we soon found out that she was actually Ze- I won’t spoil it for you“. It’s small little insertions like that which give the game a personification, and that’s just one example of the many embedded within this game. It’s cool to see techniques that I believe very strongly in being used in such a successful franchise, such as Smash Bros.

You can see output of these lines in action on my earlier post about the game. It’s very simple, but effective and easy. I’ll probably end up adding an array of previously selected lines to ensure the diversity in the lines, and that the user doesn’t get the same one twice in a single game session, but for now I’ll share with you the code as it is:

//Words of Disappointment
string incorrectAnswer(){
    
    // Gives rand() a new seed
    srand ( time(NULL) );

    // Creates random int using rand()
    int random = rand() % 16;
    
    
    if(random == 0){
        return "OUCH! I'm sorry, that's wrong... ";
    }
    
    if(random == 1){
        return "SO CLOSE.... just kidding I really don't know.. ";
    }
    
    if(random == 2){
        return "I believe in you! But maybe I shouldn't have that time... ";
    }
    
    if(random == 3){
        return "You wouldve done awesome on that one, if task was to do terribly... ";
    }
    
    if(random == 4){
        return "Well... You tried! ";
    }
    
    if(random == 5){
        return "Nice one!! Just kidding, that's really wrong..";
    }
    
    if(random == 6){
        return "Have you not been paying attention..?";
    }
    
    if(random == 7){
        return "You're wronger than the word \"wronger\" sounds..";
    }
    
    if(random == 8){
        return "Don't you know how long it took me to make this game?? The least you can do is get the answers correct!";
    }
    
    if(random == 9){
        return "Close, but no cigar..";
    }
    
    if(random == 10){
        return "OOF... That one hurt me too :(";
    }
    
    if(random == 11){
        return "Remember Tom & Jerry..? You're really acting like Tom rightn now..";
    }
    
    if(random == 12){
        return "Sometimes... effort just isn't enough..";
    }
    
    if(random == 13){
        return "I wish I could help you... cause you really need it..";
    }
    
    if(random == 14){
        return "Randomly generated generic response to your ignorance #120321: \"You embarass me\"";
    }
    
    if(random == 15){
        return "Eat a can of spinnach.. or do something, just stop being wrong..";
    }


    
    else return "Well... That shouldn't have happened... but you're also incorrect.. ";
}



//Words of Wisdom
string wordsOfWisdom(){
  
   
    // Gives rand() a new seed
    srand ( time(NULL) );
    
    // Creates random int using rand() from 
    int random = rand()%31;
    
    //Random responses
    if(random == 0){
        return "Never look back.. You dont have time for that!";
    }
    
    
     if(random == 1){
        return "Time is the one thing you can never get back... and you're wasting it!";
    }
    
    
     if(random == 2){
        return "Smile more... please!!";
    }
    
    
     if(random == 3){
        return "Don't overthink this..";
    }
    
    
     if(random == 4){
        return "Lightning strikes the earth about 100 times every second... That's like 300 times since you started reading this..!";
    }
    
    
     if(random == 5){
        return "Are you enjoying yourself?? Let me know! +1(805)231-1561";
    }
    
    
     if(random == 6){
        return "Try listening to faster paced music maybe.?";
    }
    
    
     if(random == 7){
        return "Open a window! Fresh air is good for you!";
    }
    
    
     if(random == 8){
        return "Carrot cake is perhaps one of the best collabs we've ever seen.. it evolved from carrot pudding! Sounds much less appetizing..";
    }
    
    
     if(random == 9){
        return "Cool game, huh?";
    }
    
    if(random == 10){
        return "Theres billions of people in this world... your small mistakes really don't matter much!";
    }
    
    if(random == 11){
        return "Can you do a cartwheel?? Show me!";
    }
    
    if(random == 12){
        return "Don't trip chocolate chip.";
    }
    
    if(random == 13){
        return "Simpossible because it's so simple... but still impossible... get it now?";
    }
    
    if(random == 14){
        return "I hope some of these little words of wisdom have made you smile!";
    }
    
    if(random == 15){
        return "You're wonderful!";
    }
    
    if(random == 16){
        return "That was so quick I didn't even see your fingers move!";
    }
    
    if(random == 18){
        return "Check out my mixtape: 11101101000110100";
    }
    
    if(random == 19){
        return "Lo Hicimos!";
    }
    
    if(random == 20){
        return "Don't copy and paste code kids! That's how bugs are spread!";
    }
    
    if(random == 21){
        return "Every correct answer is another byte of RAM I consume!";
    }
    
    if(random == 22){
        return "High levels of arousal are best for simple tasks, such as these! Check out Yerkes-Dodson Law!";
    }
    
    if(random == 23){
        return "They did surgery.. on a grape!!! (This meme is probably long dead..)";
    }
    
    if(random == 24){
        return "RIP all the hours you've spent on this game...";
    }
    
    if(random == 25){
        return "Kanpai!";
    }
    
    if(random == 26){
        return "Salud!";
    }
    
    if(random == 27){
        return "Cheers!";
    }
    
    if(random == 28){
        return "Skål!";
    }
    
    if(random == 29){
        return "Spread love and acceptance, and the world may become a better place yet!!";
    }
    
    if(random == 30){
        return "Read more Tolkien! (Not paid for by the Tolkien Trust).";
    }
    
    else return "Well... That shouldn't have happened!";
}

Simpossible Initial Overview and Code

Hello there!

I haven’t been very active here these last few months, my apologies! I’ve been swamped with my classes. But all is well, classes are going really well for me, but the only downside is my free time to program and work on passion projects has been effectively consumed by the amount of work my classes have been requiring. However, as finals week approaches I have had a little more time to be working on a game which I started a few months back.

The game I’ve been working on I have titled Simpossible. It’s essentially a game of mini games, all done through text. It’s in C++, and is built entirely upon speed. The score increases with each quick minigame, and the faster a task is completed, the higher the score for that specific game. by quick, I mean very quick. The game will cut you off at 10 seconds, which is achievable at the start, but as difficulty of tasks increases, this time limit becomes a serious constraint.

A big thing I’ve been trying to do with this project is give the game a personality of it’s own. I’ll post more on that in the future, but as you look at output, take notice of the little, what I’ve called, words of wisdom and words of disappointment. So far, I’ve put in about 25 unique lines for both, but I would like to have it around 100 or so by the time I’ve finished the project, but as it’s extremely simple to add to, I just haven’t taken the time yet… IM BUSY!

So far, I’ve created only 4 minigames, but hope to come to about 10 by the time I am finished. Each round is comprised of 5 “events”, each one of them being a try at one of the minigames, randomly selected. The player has 3 lives, which are lost by incorrect answers. The punishment for not meeting the time constraint is no points for the event. The games so far include the following:

Math Game:

The simplest of the games to explain, the user is given a problem to solve and must answer the problem correctly. Starting with simple addition and eventually elevating to include all operations and order of operations. The challenge is I must keep it simple enough that most would be able to reasonably solve even the most difficult of these problems within 14 seconds at most. This is important because the game must remain competitive and fun even at the higher difficulties. I’ll post code at bottom, but heres some output:

Screen Shot 2018-11-29 at 3.36.51 PMScreen Shot 2018-11-29 at 3.35.32 PM

Repeat After Me:

This game just creates a random string of letters that the user must replicate within the time limit. The letters are truly random, so as of now they are absolute gibberish… I have considered pairing this program with a file of the english lexicon and possibly just pulling random words from there, but I think that would be too easy for the player, and there’s something I really find fun and interesting about the output of completely random strings. As difficulty increases, the string is lengthened to add more nonsense. Heres some output, I’ll include some code at the bottom:

Screen Shot 2018-11-29 at 3.37.35 PM

(looking at the output, it looks a little lame super fun! )

But I do promise it’s actually a lot of fun to play around with!

Let’s Dance:

Let’s dance is my favorite game I’ve implemented so far. It feeds you a series of directions and you have to respond to those directions one at a time, to replicate the idea of DDR. It’s actually a lot of fun. I had to resort to using the WASD keys as opposed to arrow keys, because I couldn’t find a way to make the arrows work for both MAC OS and Windows, but it doesn’t take away from the idea of things, or at least I don’t think. Here’s some output:

Screen Shot 2018-11-29 at 3.36.18 PM

Roman Numeral Game:

The last game that I’ve just started working on implementing is a roman numeral identification game. It’s going to feed the user randomly generated roman numerals, and the player must translate them into the numbers we know and love. While simple at first, the game is going to go on to involve numbers which not everybody may be able to decipher. I’m still working on this game, and trying to emphasize playability, because I know this one could be a little tougher for some.

Here’s some code:

/*
 
 
    Math Game
 
 
 */


//Math Game
bool mathGame(int difficulty){

    //Seeds Rand
    srand ( time(NULL) );

    /*
     
        Difficulty 0 - 2
     
     */
    
    if(difficulty <= 2){
        
        
        //Generates vars & decides operation
        int var1 = (rand() % 11) * difficulty;
        int var2 = (rand() % 11) * difficulty;
        int operation = rand() % 2;
        int answer;
        
        
        //Addition operation
        if(operation == 0){
            
           
            cout << var1 << " + " << var2 << " = ";             cin >> answer;
            
            //Wrong Answer
            if(answer != var1+var2){
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;
                sleep(3);
                return false;
            }
            
            //Correct Answer
            else return true;
        }
        
        //subtraction operation
        else if(operation == 1){
            
            
            cout << var1 << " - " << var2 << " = ";             cin >> answer;
            
            //Wrong Answer
            if(answer != var1-var2){
               
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;                 sleep(3);                 return false;             }                          //Correct Answer             else return true;         }     }               /*               Difficulty 3 - 6            */               //Increase in difficulty     else if(difficulty > 2 && difficulty <= 6){
        
        
        //Creates random vars & decides operation. The random vars increase in size as the difficulty goes up.
        int var1 = (rand() % (20 + difficulty));
        int var2 = (rand() % (20 + difficulty));
        int var3 = (rand() % (20 + difficulty));
        int operation = rand() % 2;
        int answer;
        
        
        //Addition operation
        if(operation == 0){
            
            
            cout << var1 << " + " << var2 << " + " << var3 << " = ";             cin >> answer;
            
            //Wrong Answer
            if(answer != var1+var2+var3){
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;
                sleep(3);
                return false;
            }
            
            //Correct Answer
            else return true;
        }
        
        //subtraction operation
        else if(operation == 1){
            
            
            cout << var1 << " - " << var2 <<  " + " << var3 << " = ";             cin >> answer;
            
            //Wrong Answer
            if(answer != (var1-var2)+var3){
                
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;                 sleep(3);                 return false;             }                          //Correct Answer             else return true;                      }                                         }               /*            Difficulty 7 - 10            */               //Increase in difficulty     else if(difficulty > 6 && difficulty <= 10){
        
        
        //Creates random vars & decides operation. The random vars increase in size as the difficulty goes up.
        int var1 = (rand() % (20 + difficulty));
        int var2 = (rand() % (20 + difficulty));
        int var3 = (rand() % (20 + difficulty));
        int operation = rand() % 3;
        int answer;
        
        
        //Addition operation
        if(operation == 0){
            
            
            cout << var1 << " + " << var2 << " + " << var3 << " = ";             cin >> answer;
            
            //Wrong Answer
            if(answer != var1+var2+var3){
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;
                sleep(3);
                return false;
            }
            
            //Correct Answer
            else return true;
        }
        
        //subtraction operation
        else if(operation == 1){
            
            
            cout << var1 << " - " << var2 <<  " + " << var3 << " = ";             cin >> answer;
            
            //Wrong Answer
            if(answer != (var1-var2)+var3){
                
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;
                sleep(3);
                return false;
            }
            
            //Correct Answer
            else return true;
            
        }
        
        //Multiplication Operation
        else if(operation == 2){
            
            
            //Lowers random vars for sake of doability
            var1 -= 15;
            var2 -= 15;
            
            cout << var1 << " * " << var2 << " = ";             cin >> answer;
            
            //Wrong answer
            if(answer != (var1*var2)){
                
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;                 sleep(3);                 return false;             }                          //Correct             else return true;         }     }               /*            Difficulty 11 - 15            */               //Increase in difficulty     else if(difficulty > 10 && difficulty <= 15){
        
        
        //Creates random vars & decides operation. The random vars increase in size as the difficulty goes up.
        int var1 = (rand() % (20 + difficulty));
        int var2 = (rand() % (20 + difficulty));
        int var3 = (rand() % (20 + difficulty));
        int operation = rand() % 4;
        int answer;
        
        
        //Addition operation
        if(operation == 0){
            
            
            cout << var1 << " + " << var2 << " + " << var3 << " = ";             cin >> answer;
            
            //Wrong Answer
            if(answer != var1+var2+var3){
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;
                sleep(3);
                return false;
            }
            
            //Correct Answer
            else return true;
        }
        
        //subtraction operation
        else if(operation == 1){
            
            
            cout << var1 << " - " << var2 <<  " + " << var3 << " = ";             cin >> answer;
            
            //Wrong Answer
            if(answer != (var1-var2)+var3){
                
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;
                sleep(3);
                return false;
            }
            
            //Correct Answer
            else return true;
            
        }
        
        //Multiplication Operation
        else if(operation == 2){
            
            
            //Lowers random vars for sake of doability
            var1 -= 15;
            var2 -= 15;
            var3 -= 15;
            
            cout << var1 << " * " << var2 << " * " << var3 << " = ";             cin >> answer;
            
            //Wrong answer
            if(answer != (var1*var2*var3)){
                
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;
                sleep(3);
                return false;
            }
            
            //Correct
            else return true;
        }
        
        //PemDas Operation
        else if(operation == 3){
            
            
            var1 -= 15;
            
            cout << var1 << "(" << var2 << " + " << var3 << ") = ";             cin >> answer;
            
            //Wrong answer
            if(answer != ((var2+var3)*var1)){
                
                lives--;
                cout << incorrectAnswer() << " You have " << lives << " lives left." << endl << endl;
                sleep(3);
                return false;
            }
            
            //Correct
            else return true;
            
        }
    }

        

    
    return false;
}

/*
 
    Repeat After Me
 
 */

//Repeat After Me Game
bool repeatAfterMe(int difficulty){
    
    //Basic instructions
    cout << "Repeat after me!! " << endl;
    sleep(2);
        
    char letter;
    string sentence;
    string answer;
    int temp;
        
        
    //initialize random num generator
    srand (time(0));
    
    
    //Loop to increase size of repeat after me by difficulty
    for(int rep = 0; rep <= difficulty+3; rep++){
        
        //generates random number
        temp = rand() % 26;
            
        //converts number to letter
        letter = 'a' + temp;
        sentence += letter;
    }
    
    //prints out the "sentence"
    cout << sentence << endl;          //takes user's input     cin >> answer;
    
    //compares the user's input to the specified string
    if(answer == sentence) return true;
    
    
    else{
        
        lives --;
        cout << incorrectAnswer() << " You have " << lives << " lives left! " << endl << endl;
        
        //returns false
        return false;
    }
}


 

Heapsort in Java

This program sorts data of type E in “heapsort” fashion. Read more about heapsort here.

The class extends an abstract class “sorter”, provided below. This abstract class was written by Adam Smith. The array that is being sorted is set to the size of 500, and is filled with random ints to best test the sorter. This can be altered in the main. For a visual demonstration of many sorting methods, click here. This visual guide was created by Professor Adam Smith for his students.

Screen Shot 2018-01-28 at 11.49.13 AM

/**
 * Algorithm to sort an array of type E in the HeapSort fashion
 * @author AidanTakami
 * @version 1.0
 *
 */
class HeapSort extends Sorter {
	private static int top;

	/**
	 * Method which sorts array in HeapSort fashion.
	 *
	 * @param array which is going to be sorted
	 * @since 1.0
	 */
	@Override
	public <E extends Comparable<E>> void sort(E[] array){
		top = array.length - 1;
		//iterates through the array, heapifying it
		for(int rep = (top/2); rep >= 0; rep--){
			heapify(array, rep);
		}

		//iterates through the array, bringing the highest values to the top and then re heapifying
		for(int i = top; i >= 0; i--){
			E oldValue = array[0];
			array[0] = array[i];
			array[i] = oldValue;
			top--;
			heapify(array, 0);
		}
		//Not sure as to why, but sometimes leaves first 3 elements unsorted. This is a temporary bug fix.
		if(array[1].compareTo(array[2]) > 0){
			E iMadeAnError = array[2];
			array[2] = array[1];
			array[1] = iMadeAnError;
		}
		if(array[0].compareTo(array[1]) > 0){
			E iMadeAnError = array[1];
			array[1] = array[0];
			array[0] = iMadeAnError;
		}

	}
	/**
	 * Method which uses the parameter array and the parameter rep to compare rep to it's children
	 * and then sink rep if it is < a child, and then call itself to sink rep until rep > it's children
	 *
	 * @param array which will be heapified
	 * @param int rep which will be compared to it's children
	 * @since 1.0
	 */
	public <E extends Comparable<E>> void heapify(E[] array,int max){

			//allocates ints for the location of the node's children, and the parent.
			int right = 2 * max+2, left = 2 * max+1, i = max;

			//makes sure the right child's index isnt too high, then compares it to max
			if(right <= top - 1 && array[right].compareTo(array[max]) > 0){
				//sets the max = the right child
				max = right;
			}

			//makes sure the left child's index isnt too high, then compares it to max
			if(left <= top - 1 && array[left].compareTo(array[max]) >= 0){
				//sets the max = the left child
				max = left;
			}

			//makes sure the max has been reset before heapifying again, and sinking the values
			if(max != i){
				sink(array, i, max);
				heapify(array, max);
			}
	}
	//sinks the element at location lesserValSpot, and swaps it with the element at greaterValSpot
	private <E extends Comparable<E>> void sink(E[] array, int lesserValSpot, int greaterValSpot){
		E oldParent = array[lesserValSpot];
		array[lesserValSpot] = array[greaterValSpot];
		array[greaterValSpot] = oldParent;
	}

	/**
	 * Main function to test the HeapSort
	 *
	 * @since 1.0
	 */
	public static void main(String[] args){
		Integer[] arr = new Integer[500];
		for(int rep = 0; rep < arr.length; rep++){
			Integer random =(int )(Math.random() * arr.length + 0);
			arr[rep] = random;
		}

		System.out.print("The unsorted Array: [");
		for(int i = 0; i < arr.length; i++){
			System.out.print(arr[i] + ", ");
		}
		System.out.println("]");

		System.out.print("The sorted Array: [");
		new HeapSort ().sort(arr);
		for(int i1 = 0; i1 < arr.length; i1++){
			System.out.print(arr[i1] + ", ");
		}
		System.out.println();
		double time = new HeapSort().timeSort(500);
		System.out.println("The Array is sorted? " + isSorted(arr));
		System.out.println("The sort took : " + time + " Millisecond(s).");

	}
}

/**
 * Base abstract class for Sorters of various kinds.
 *
 * @author Adam Smith
 * @version 1.0
 */

public abstract class Sorter {
	/**
	 * Do the actual sorting.
	 *
	 * @param array  the array to sort
	 */

	abstract public <E extends Comparable<E>> void sort(E[] array);

	/**
	 * Tells whether or not an array is sorted. Useful for
	 * assertions. Will also return false if one of the elements is
	 * null.
	 *
	 * @param array  the array that may be sorted
	 * @return      whether or not it's sorted
	 */

	public static final <E extends Comparable<E>> boolean isSorted(E[] array) {
		if (array[0] == null) return false;

		// go thru each element, testing for order
		for (int i=1; i<array.length; i++) {
			if (array[i] == null) return false;
			if (array[i].compareTo(array[i-1]) < 0) return false;
		}

		// return true if we finished the loop without problem
		return true;
	}

	/**
	 * Times a sort of an array of a particular size. This method
	 * creates a new array of Integers of the given size, and gives
	 * each one a random value between 0 and the size. (Thus,
	 * duplicate values are almost certainly present, but uncommon.)
	 * It then returns the number of milliseconds this took, not
	 * including time taken to allocate the array and its components.
	 *
	 * @param size  the number of elements to be sorted
	 * @return      the number of milliseconds taken
	 */

	public final int timeSort(int size) {
		// allocation
		Integer[] array = new Integer[size];
		for (int i=0; i<array.length; i++) array[i] = new Integer((int)(Math.random() * size));

		// do the sort now, returning # ms
		long start = System.currentTimeMillis();
		sort(array);
		return (int)(System.currentTimeMillis() - start);
	}
}

Unity Crash Destroys My Happiness

Well, shit… After spending a few days working on an order taking software based off of my job at In N Out, a Unity crash proved to be all it took for me to lose all progress. Since the software was only 1 scene, that scene has been completely wiped. Despite my good saving habits, and having exited out of Unity3D multiple times, and still having my project, this one crash seems to have completely wiped all my progress (except for my code). Everything carries a lesson and the lesson i’ve learned from this is after a Unity crash, to not re open Unity, but instead find out  of the automatic backups stored in the “temp” folder under assets. Save yourself time, & sanity, and learn from my mistakes.

 

All that aside, I still have some interesting code and was working with some interesting ways in which I could store & display an order in progress, as well as a completed order. Using a generic type “BurgerObject”, that take the specific type of burger as a string, and have the ingredients stored in a List, I am able to accurately recreate how order taking works across all In N Out store locations. In addition to this, using the buttons that I had placed across the scene to represent each item would add a new text to the screen, representing the burger/item added, adding it to the entirety of the order. I found it difficult to decide how I was going to best display the entire order, since the order is stored in a List and displaying a List seems to be pretty much undoable in C#, but found this way to be likely the most promising. Here’s some code (please know that this is not nearly completed, just posting what I had completed pre crash):

 

Screen Shot 2018-07-26 at 11.59.28 AMScreen Shot 2018-07-26 at 11.58.07 AMScreen Shot 2018-07-26 at 11.58.14 AM

My Summer “Break”

Hello all! As I’m sure you can see from the gap of time since my last post, I haven’t been as active on here as normal. I’ve spent my summer up to this point working a lot on developing my skills within Unreal Engine 4, making use of the online course program called Udemy. Specifically, I have been taking the course “The Unreal Engine Developer Course” posted and instructed by Professor Ben Tristem. I’ve learned a lot of great new skills from this course, but am far from finished. I’m hoping to have completed the course in it’s entirety by the end of the summer. But I’m here to make this post to first of all update all on where I have bee, as well as speak to why I find Udemy such a useful platform. Online courses can be a struggle, but Udemy is perhaps the best form an online course can take. The platform makes it seamless to contact my professors, view other student’s previously answered questions, and push myself and really track my own progress based on the scores of quizzes I take. There is tons of programming courses on Udemy of all languages not just C++, & I would highly recommend it to anyone trying to sharpen their skills or learn a new language. I will try to be more frequently on here for the remainder of the Summer, but want to thank you all for stopping by and hearing my 2 cents.

Quicksort

Hello! Below is my attempt at a quicksort. Sorters are really interesting code because they can be done in so many different ways, which can make such a difference in the speed an array is sorted. Here (No longer online :(, here’s another) is a visual example from my old professor Adam Smith. From this visual guide, you’re able to see when quicksort is most and least effective. Here’s some output:

Screen Shot 2018-02-02 at 12.00.27 PMScreen Shot 2018-02-02 at 12.01.15 PM

//
//  Quicksort2.cpp
//
//  Sorter which will sort array of random values in the "quicksort" style.
//
//  Created by Aidan Takami on 2/1/18.
//  Copyright © 2018 Aidan Takami. All rights reserved.
//


/*
     Must include iostream, cstdlib, and ctime. Site keeps deleting
     these libraries thinking they are HTML tags
/*
#include 
#include 
#include 



using namespace std;

void printArray(int r[]);
void switchValues(int r[], int, int);
void randmoArray(int r[]);
void quickSort(int r[], int, int);

//Declares the array to be sorted, as well as the const to represent the size of the array
int r[100];
const int SIZE = (sizeof(r)/4);


//Method to print out values of the array
void printArray(int r[])
{
    int i=0;
    while(i<SIZE){
        cout<<r[i]<<",";
        i++;
    }
}


//Method to swap the values at the locations of the 2 int args, within the array provided
void switchValues(int r[],int leftSide, int rightSide){
    int temp = r[leftSide];
    r[leftSide] = r[rightSide];
    r[rightSide] = temp;
}

//Method which will randomize an array of the size of the const int SIZE
void randomArray(int r[]){
    
    for(int rep = 0; rep < SIZE; rep++){
        
        r[rep] = int (rand()%100);
    }
}


//Quicksort method
void quicksort(int r[], int leftSide, int rightSide){
    
    int leftTemp = leftSide;
    int rightTemp = rightSide;
    int pivot = r[(leftSide+rightSide)/2];
    
    while(leftSidepivot)
            rightTemp--;
        
        if(leftTemp<=rightTemp){
            switchValues(r, leftTemp, rightTemp);
            leftTemp++;
            rightTemp--;

        }
        else{
            if(leftSide<rightTemp)
                quicksort(r, leftSide, rightTemp);
            if(leftTemp<rightSide)
                quicksort(r,leftTemp,rightSide);
            return;
        }
    }
}


//Main method for testing the quicksort
int main() {
  
    cout << "Generating random array!" << endl;
    randomArray(r);
    
    cout << "The unsorted array: ";
    printArray(r);
    
    cout << endl << endl;
    cout << "Sorting in progress..." << endl;
    const clock_t beginTime = clock();
    quicksort(r, 0, SIZE);
    float totalTime = ( clock () - beginTime ) /  CLOCKS_PER_SEC;
    
    cout << "The sorted array: ";
    printArray(r);
    cout << endl;
    
    cout << "The sort took " << totalTime << " milliseconds!" << endl;
    
    return 0;
}

Game Update: Tic Tac Toe

After finishing up my Tic Tac Toe AI, I was left wondering: “Is this bot really the best Tic Tac Toe competitor I can create?”, so I went to work towards another concept of AI to compete in my game versus the original bot. Below are details of the 2 bots, as well as a link to the .pdf showing the outcome of their 10,000 matchups.

 

CPU 1 is the original bot I created a few days back. The code can be accessed in the link above. This bot takes a unique approach every turn, excluding the final two turns. The first turn it will default to the middle box (spot 5), or, if that is occupied, the bottom right box (spot 9). From there it will place its next 2 pieces according to how it’s opponent is trying to play. If the opponent is aggressive in trying to get 3 in a row, it will play defensively. If the opponent is more lax in their approach, the bot will go for the win. The bot has every possible situation, and the appropriate response, hard coded into it’s programming for turns 2 & 3. Turns 4 & 5 the bot looks for any possible opportunity, by either player, to win the match, and places it’s piece in the spot that would complete the 3 in a row. If none can be found, it simply places in a random open space.

 

CPU 2 is the bot I created in an attempt to out play my previous bot. The bot’s moves are decided very basically on whether or not the bot has a chance to win. In a kind of “bogo sort” fashion, the bot will make it’s first move at complete random, since the first move is rather insignificant. From there it gauges the opponent’s move, decides whether or not the opponent has a chance to win (not by using specific spot numbers but instead the overall state of the board), and if so defends the move, and if not places it’s piece in the way it deems easiest to get a 3 in a row. This move is the repeated for the rest of the game.

 

Click here to view the stat sheet.

 

In conclusion, as of now the original AI is by far the superior, but it would be preferable to decrease the overall number of draws, and perhaps make the bot more aggressive, resulting in more wins.

Game Sample: Tic Tac Toe AI

Over the last few weeks I have been implementing a bot into my Tic Tac Toe program, allowing a single player to test their skills at tic tac toe, while also sharpening my skills in regards to writing AI. The bot has proven to be a somewhat tedious, but very successful attempt at Artificial Intelligence. After many hours of testing, and improvising (and nearly 2000 lines of code), I believe it to be unbeatable… while I’m sure there is a flaw in there somewhere, I am unable to find it. I will continue to improvise and improve the bot, but for the time being, it is completed! Here is some gameplay (Just a note: the bot always plays as player 2 (O)):

Screen Shot 2018-04-04 at 1.46.34 AMScreen Shot 2018-04-04 at 1.46.59 AMScreen Shot 2018-04-04 at 1.47.26 AM

//
//  main.cpp
//  Tic Tac Toe
//
//  Created by Aidan Takami on 3/8/18.
//  Copyright © 2018 Aidan Takami. All rights reserved.
//

#include 
#include 

using namespace std;

//Array to represent the spots on the board
char spot[10] = {'o','1','2','3','4','5','6','7','8','9'};
char cpuChoices[5]{0,0,0,0,0};

int ifWon();
void singlePlayer();
void cpuTurn(int);
void board();
void clearBoard();
void clearCpu();
bool cpuChoicesContains(char);
int findSpot();

//Main method
int main()
{
    
    cout << "\n\n\tTic Tac Toe\n\n";
    
    
    //Allows player to play vs CPU or human
    
    string temp;
    cout << "Would you like to play with 2 players, or 1? (enter 1 or 2)" << endl;     cin >> temp;
    
    if(temp == "1"){
        singlePlayer();
    }

start:

    int player = 1,i = -1,choice;

    char side, playOn;
    
    //Game loop, which will continue while no player has won
    while(i==-1){
        
        //Draws the board
        board();
        
        //Deciphers which players turn it is, using the modulus operator
        player=(player%2)?1:2;
        
        //Intro text & takes players move
        cout << "Player " << player << ", enter a number:  ";         cin >> choice;
        
        //Decides the team that the current player is on (X's or O's)
        side=(player == 1) ? 'X' : 'O';
        
        
        //Will take the player's move and mark the correct box (if unoccupied) with the correct side
        if (choice == 1 && spot[1] == '1')
            
            spot[1] = side;
        else if (choice == 2 && spot[2] == '2')
            
            spot[2] = side;
        else if (choice == 3 && spot[3] == '3')
            
            spot[3] = side;
        else if (choice == 4 && spot[4] == '4')
            
            spot[4] = side;
        else if (choice == 5 && spot[5] == '5')
            
            spot[5] = side;
        else if (choice == 6 && spot[6] == '6')
            
            spot[6] = side;
        else if (choice == 7 && spot[7] == '7')
            
            spot[7] = side;
        else if (choice == 8 && spot[8] == '8')
            
            spot[8] = side;
        else if (choice == 9 && spot[9] == '9')
            
            spot[9] = side;
        
        //If selected box is occupied
        else
        {
            cout<<"Invalid move ";
            
            //gives the same player another turn
            player--;
            cin.ignore();
            cin.get();
        }
        
        //determines if the board contains a win or draw.
        i=ifWon();
        
        //Continues the play process
        player++;
    }
    
    //If a player won, draws the board and announces who won
    board();
    if(i==1)
        
        cout<<"Player "<<--player<<" wins! ";
    
    //If draw, announces a draw
    else
        cout<<"==>\aGame draw";
    
    
    //Gives players an option to play again
    cout << " Would you like to play again? (y/n)" << endl;     cin >> playOn;
    
    if(playOn == 'y' || playOn == 'Y' ){
        clearBoard();
        goto start;
    }
    
    else
    exit(0);
}

//function that returns the result of the game

int ifWon()
{
   
    //Game was won
    if (spot[1] == spot[2] && spot[2] == spot[3])
        return 1;
    else if (spot[4] == spot[5] && spot[5] == spot[6])
        
        return 1;
    else if (spot[7] == spot[8] && spot[8] == spot[9])
        
        return 1;
    else if (spot[1] == spot[4] && spot[4] == spot[7])
        
        return 1;
    else if (spot[2] == spot[5] && spot[5] == spot[8])
        
        return 1;
    else if (spot[3] == spot[6] && spot[6] == spot[9])
        
        return 1;
    else if (spot[1] == spot[5] && spot[5] == spot[9])
        
        return 1;
    else if (spot[3] == spot[5] && spot[5] == spot[7])
        
        return 1;
    
    
    //Game was a draw
    else if (spot[1] != '1' && spot[2] != '2' && spot[3] != '3'
             && spot[4] != '4' && spot[5] != '5' && spot[6] != '6'
             && spot[7] != '7' && spot[8] != '8' && spot[9] != '9')
        
        return 0;
    
    
    //Game still in progress
    else
        return -1;
}



//Function that draws the board
void board()
{
 
    cout << endl << endl << endl;
    
    //Prints each box of the board with the contents of the array properly alligned
    cout << "Player 1 (X)  -  Player 2 (O)" << endl << endl << endl;
    cout << "     |     |     " << endl;
    cout << "  " << spot[1] << "  |  " << spot[2] << "  |  " << spot[3] << endl;
    cout << "_____|_____|_____" << endl;
    cout << "     |     |     " << endl;
    cout << "  " << spot[4] << "  |  " << spot[5] << "  |  " << spot[6] << endl;
    cout << "_____|_____|_____" << endl;
    cout << "     |     |     " << endl;
    cout << "  " << spot[7] << "  |  " << spot[8] << "  |  " << spot[9] << endl;
    cout << "     |     |     " << endl << endl;
}



//Method to allow player to play versus a CPU
void singlePlayer(){
    
start:
    
    int player = 1,i = -1,choice, round = 0;
    
    char side, playOn;
    
    //Game loop, which will continue while no player has won
    while(i==-1){
        
        //Deciphers which players turn it is, using the modulus operator
        player=(player%2)?1:2;
        
        //Draws the board for user
        if(player == 1)
            board();
        
        //Intro text & takes players move
        cout << "Player " << player << ", enter a number:  ";
        
        if(player == 2){
            cpuTurn(round);
            cout << "CPU turn!" << endl;         }         else{                      cin >> choice;
        
            //Decides the team that the current player is on (X's or O's)
            side=(player == 1) ? 'X' : 'O';
        
        
            //Will take the player's move and mark the correct box (if unoccupied) with the correct side
            if (choice == 1 && spot[1] == '1')
                spot[1] = side;
            
            else if (choice == 2 && spot[2] == '2')
            
                spot[2] = side;
            else if (choice == 3 && spot[3] == '3')
            
                spot[3] = side;
            else if (choice == 4 && spot[4] == '4')
            
                spot[4] = side;
            else if (choice == 5 && spot[5] == '5')
            
                spot[5] = side;
            else if (choice == 6 && spot[6] == '6')
            
                spot[6] = side;
            else if (choice == 7 && spot[7] == '7')
            
                spot[7] = side;
            else if (choice == 8 && spot[8] == '8')
            
                spot[8] = side;
            else if (choice == 9 && spot[9] == '9')
            
                spot[9] = side;
        
            //If selected box is occupied
            else
            {
                cout<<"Invalid move ";
            
                //gives the same player another turn
                player--;
                cin.ignore();
                cin.get();
            }
        }
        
        //determines if the board contains a win or draw.
        i=ifWon();
        
        //Continues the play process
        player++;
        round++;
    }
    
    //If a player won, draws the board and announces who won
    board();
    if(i==1)
        
        cout<<"Player "<<--player<<" wins! ";
    
    //If draw, announces a draw
    else
        cout<<"==>\aGame draw";
    
    
    //Gives players an option to play again
    cout << " Would you like to play again? (y/n)" << endl;     cin >> playOn;
    
    if(playOn == 'y' || playOn == 'Y' ){
        clearBoard();
        clearCpu();
        goto start;
    }
    
    else
        exit(0);

}


//AI to play against the player in single player mode
//Organized by turn.
void cpuTurn(int round){
    
    //in the first round
    if(round == 1){
      
        //AI will try to get the middle of the board
        if(spot[1] == 'X' || spot[2] == 'X' || spot[3] == 'X' || spot[4] == 'X'){
            spot[5] = 'O';
            cpuChoices[0] = '5';
        }
        
        else if(spot [6] == 'X' || spot [7] == 'X' || spot[8] == 'X' || spot[9] =='X'){
            spot[5] = 'O';
            cpuChoices[0] = '5';
        }
        
        //Otherwise, AI will go for spot 9
        else{
            spot[9] ='O';
            cpuChoices[0] = '9';
        }
    }
    
    
    //Second turn
    if(round == 3){
        
        
        //AI will decide based upon previous moves by both AI and user
        if(spot[1] == 'X' && spot[2] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[3] = 'O';
                cpuChoices[1] = '3';
            }
        }
        
        else if(spot[1] == 'X' && spot[3] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[2] = 'O';
                cpuChoices[1] = '2';
            }
        }
        
        else if(spot[1] == 'X' && spot[4] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[7] = 'O';
                cpuChoices[1] = '7';
            }
        }
        
        else if (spot[1] == 'X' && spot[5] == 'X'){
            spot[3] = 'O';
            cpuChoices[1] = '3';
        }
        
        else if(spot[1] == 'X' && spot[6] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[2] = 'O';
                cpuChoices[1] = '2';
            }
        }
        
        else if(spot[1] == 'X' && spot[7] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[4] = 'O';
                cpuChoices[1] = '4';
            }
        }
        
        else if(spot[1] == 'X' && spot[8] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[3] = 'O';
                cpuChoices[1] = '3';
            }
        }
        
        else if(spot[1] == 'X' && spot[9] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[2] = 'O';
                cpuChoices[1] = '2';
            }
        }
        
        
        
        else if(spot[2] == 'X' && spot[3] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[1] = 'O';
                cpuChoices[1] = '1';
            }
        }
        
        else if(spot[2] == 'X' && spot[4] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[1] = 'O';
                cpuChoices[1] = '1';
            }
        }
        
        else if(spot[2] == 'X' && spot[5] == 'X'){
                spot[8] = 'O';
                cpuChoices[1] = '8';
        }
        
        else if(spot[2] == 'X' && spot[6] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[1] = 'O';
                cpuChoices[1] = '1';
            }
        }
        
        else if(spot[2] == 'X' && spot[7] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[1] = 'O';
                cpuChoices[1] = '1';
            }
        }

        else if(spot[2] == 'X' && spot[8] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[1] = 'O';
                cpuChoices[1] = '1';
            }
        }
        
        else if(spot[2] == 'X' && spot[9] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[3] = 'O';
                cpuChoices[1] = '3';
            }
        }
        
        
        
        else if(spot[3] == 'X' && spot[4] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[1] = 'O';
                cpuChoices[1] = '1';
            }
        }
        
        else if(spot[3] == 'X' && spot[5] == 'X'){
                spot[7] = 'O';
                cpuChoices[1] = '7';
        }
        
        else if(spot[3] == 'X' && spot[6] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[9] = 'O';
                cpuChoices[1] = '9';
            }
        }
        
        else if(spot[3] == 'X' && spot[7] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[1] = 'O';
                cpuChoices[1] = '1';
            }
        }
        
        else if(spot[3] == 'X' && spot[8] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[9] = 'O';
                cpuChoices[1] = '9';
            }
        }
        
        else if(spot[3] == 'X' && spot[9] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[6] = 'O';
                cpuChoices[1] = '6';
            }
        }
        
        
        
        else if(spot[4] == 'X' && spot[5] == 'X'){
                spot[6] = 'O';
                cpuChoices[1] = '6';
        }
        
        else if(spot[4] == 'X' && spot[6] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[9] = 'O';
                cpuChoices[1] = '9';
            }
        }
        
        else if(spot[4] == 'X' && spot[7] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[1] = 'O';
                cpuChoices[1] = '1';
            }
        }
        
        else if(spot[4] == 'X' && spot[8] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[9] = 'O';
                cpuChoices[1] = '9';
            }
        }
        
        else if(spot[4] == 'X' && spot[9] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[3] = 'O';
                cpuChoices[1] = '3';
            }
        }

        
        
        else if(spot[5] == 'X' && spot[6] == 'X'){
                spot[4] = 'O';
                cpuChoices[1] = '4';
        }
        
        else if(spot[5] == 'X' && spot[7] == 'X'){
            spot[3] = 'O';
            cpuChoices[1] = '3';
        }
        
        else if(spot[5] == 'X' && spot[8] == 'X'){
            spot[2] = 'O';
            cpuChoices[1] = '2';
        }
        

        
        else if(spot[6] == 'X' && spot[7] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[9] = 'O';
                cpuChoices[1] = '9';
            }
        }

        else if(spot[6] == 'X' && spot[8] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[9] = 'O';
                cpuChoices[1] = '9';
            }
        }

        else if(spot[6] == 'X' && spot[9] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[3] = 'O';
                cpuChoices[1] = '3';
            }
        }
        
        
        
        else if(spot[7] == 'X' && spot[8] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[9] = 'O';
                cpuChoices[1] = '9';
            }
        }
        
        else if(spot[7] == 'X' && spot[9] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[8] = 'O';
                cpuChoices[1] = '8';
            }
        }
        
        else if(spot[8] == 'X' && spot[9] == 'X'){
            if(cpuChoices[0] == '5'){
                spot[7] = 'O';
                cpuChoices[1] = '7';
            }
        }

    }
    
    
    
    //third turn
    //Most complex turn, most games are won or lost in this round
    if(round == 5){
        
        //Spots 1 & 2 taken first
        
        if(spot[1] == 'X' && spot[2] =='X'){
            
            
            if(spot[4] =='X'){
                if(cpuChoicesContains('3') && cpuChoicesContains('5')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('7')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }

            }
            
            else if(spot[5] == 'X'){
                if(cpuChoicesContains('9') && cpuChoicesContains('6')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('3')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
            }

            
            else if(spot[6] == 'X'){
                if(cpuChoicesContains('3')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('7')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
            }
            
            else if(spot[7] == 'X'){
                if(cpuChoicesContains('4')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
                else{
                    spot[4] = 'O';
                    cpuChoices[2] = '4';
                }
                
                
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('3')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('7')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('3')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('7')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
            }



            
        }
        
        
        //Spots 1 & 3 taken first
        
        
        else if(spot[1] == 'X' && spot[3] =='X'){
            
            if(spot[4] =='X'){
                if(cpuChoicesContains('2') && cpuChoicesContains('5')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(!cpuChoicesContains('7')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('7') && cpuChoicesContains('5')){
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
                
            }
            
            else if(spot[5] == 'X'){
                if(!cpuChoicesContains('9')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(!cpuChoicesContains('7')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else{
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
                
            }

            
            else if(spot[6] == 'X'){
                if(cpuChoicesContains('2') && cpuChoicesContains('5')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(cpuChoicesContains('8') && cpuChoicesContains('5')){
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
                
                else if (!cpuChoicesContains('9')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if (cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
                
            }
            
            else if(spot[7] == 'X'){
                if(cpuChoicesContains('2') && cpuChoicesContains('5')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(cpuChoicesContains('8') && cpuChoicesContains('5')){
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
                
                else{
                    spot[4] = 'O';
                    cpuChoices[2] = '4';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('2') && cpuChoicesContains('5')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('3')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }

            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('2') && cpuChoicesContains('5')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(cpuChoicesContains('8') && cpuChoicesContains('5')){
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
            }
            
            
        }
        
        //Spots 1 & 4 taken first
       else if(spot[1] == 'X' && spot[4] == 'X'){
            
             if(spot[5] == 'X'){
                if(!cpuChoicesContains('6')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('6')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
             }
            
             else if(spot[6] == 'X'){
                 if(cpuChoicesContains('7') && cpuChoicesContains('5')){
                     spot[3] = 'O';
                     cpuChoices[2] = '3';
                 }
                 
                 else if(cpuChoicesContains('2') && cpuChoicesContains('5')){
                     spot[8] = 'O';
                     cpuChoices[2] = '8';
                 }
             }
            
             else if(spot[8] == 'X'){
                 if(cpuChoicesContains('3') && cpuChoicesContains('5')){
                     spot[7] = 'O';
                     cpuChoices[2] = '7';
                 }
                 
                 else if(cpuChoicesContains('7') && cpuChoicesContains('5')){
                     spot[3] = 'O';
                     cpuChoices[2] = '3';
                 }
                 
                 else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                     spot[7] = 'O';
                     cpuChoices[2] = '7';
                 }
             }
            
             else if(spot[9] == 'X'){
                 if(cpuChoicesContains('7') && cpuChoicesContains('5')){
                     spot[3] = 'O';
                     cpuChoices[2] = '3';
                 }
                 
                 else if(cpuChoicesContains('2') && cpuChoicesContains('5')){
                     spot[8] = 'O';
                     cpuChoices[2] = '8';
                 }
                 
                 else if (cpuChoicesContains('3') && cpuChoicesContains('5')){
                     spot[7] = 'O';
                     cpuChoices[2] = '7';
                 }
             }

        }
        
        //Spots 1 & 5 taken first
        
       else if(spot[1] == 'X' && spot[5] == 'X'){
            
            if(spot[6] == 'X'){
                if(cpuChoicesContains('3') && cpuChoicesContains('9')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('4')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
            }
            
            else if(spot[7] == 'X'){
                if(cpuChoicesContains('3') && cpuChoicesContains('9')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('3') && cpuChoicesContains('9')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
                else if(cpuChoicesContains('2') && cpuChoicesContains('9')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
            }
            
            
        }
        
        
        //Spots 1 & 6 taken first
        
       else if(spot[1] == 'X' && spot[6] == 'X'){
            
            if(spot[7] == 'X'){
                if(cpuChoicesContains('5') && cpuChoicesContains('2')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('3')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
                else if(cpuChoicesContains('4') && cpuChoicesContains('5')){
                    spot[6] = 'O';
                    cpuChoices[2] = 6;
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('5') && cpuChoicesContains('2')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
            }
            
            else if(spot[9] == 'X'){
                if(!cpuChoicesContains('3')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
            }
            
        }
            
            //Spots 1 & 7 taken first
            
           else if(spot[1] == 'X' && spot[7] == 'X'){
                
                if(spot[8] == 'X'){
                    if(cpuChoicesContains('5') && cpuChoicesContains('4')){
                        spot[6] = 'O';
                        cpuChoices[2] = '6';
                    }
                    
                    else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                        spot[6] = 'O';
                        cpuChoices[2] = '6';
                    }
                }
                
                else if(spot[9] == 'X'){
                    if(cpuChoicesContains('5') && cpuChoicesContains('4')){
                        spot[3] = 'O';
                        cpuChoices[2] = '3';
                    }
                    
                    else if(cpuChoicesContains('8') && cpuChoicesContains('5')){
                        spot[2] = 'O';
                        cpuChoices[2] = '2';
                    }
                }
        }
        
        //Spots 1 & 8 taken first
        
        else if(spot[1] == 'X' && spot[8] == 'X'){
            
            if(spot[9] == 'X'){
                if(!cpuChoicesContains('7')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('7') && cpuChoicesContains('5')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
            }
        }
        
        //Spots 2 & 3 taken first
        else if(spot[2] == 'X' && spot[3] == 'X'){
            
            if(spot[4] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
            }
            
            else if(spot[5] == 'X'){
                if(cpuChoicesContains('7') && cpuChoicesContains('9')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('8')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
            }
            
            else if(spot[6] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if(spot[7] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('6')){
                    spot[4] = 'O';
                    cpuChoices[2] = '4';
                }
            }
        }
        
        //Spots 2 & 4 taken first
        
       else if(spot[2] == 'X' && spot[4] == 'X'){
            
            if(spot[5] == 'X'){
                if(cpuChoicesContains('8') && cpuChoicesContains('9')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('6')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
            }
            
            else if(spot[6] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
            }
            
            else if(spot[7] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                    spot[1] = 'O';
                    cpuChoices[2] = 1;
                }
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = '7';
                    cpuChoices[2] = '7';
                }
            }
        }
        
        //Spots 2 & 5 taken first
        
        else if(spot[2] == 'X' && spot[5] == 'X'){
            
            if(spot[6] == 'X'){
                if(cpuChoicesContains('8') && cpuChoicesContains('9')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('4') && cpuChoicesContains('9')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
            }
            
            else if(spot[7] == 'X'){
                if(cpuChoicesContains('9') && cpuChoicesContains('8')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('3')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
            }
        }
        
        //Spots 2 & 6 taken first
        
        else if(spot[2] == 'X' && spot[6] == 'X'){
            
            if(spot[7] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
                
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
            }
        }
        
        //Spots 2 & 7 taken first
        
       else if(spot[2] == 'X' && spot[7] == 'X'){
            
            if(spot[8] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('8') && cpuChoicesContains('5')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
                else if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
            }
        }
        
        //Spots 2 & 8 taken first
        
        if(spot[2] == 'X' && spot[8] == 'X'){
            
            if(spot[9] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('3')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
            }
        }

        //Spots 3 & 4 taken first
        
        else if(spot[3] == 'X' && spot[4] == 'X'){
            
            if(spot[5] == 'X'){
                if(cpuChoicesContains('9') && cpuChoicesContains('6')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('7') && cpuChoicesContains('9')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
            }
            
            else if(spot[6] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
                
            }
            
            else if(spot[7] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
            }
            
            else if (spot[8] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if (cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if (spot[9] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('6')){
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
            }
        }
        
        //Spots 3 & 5 taken first
        
       else if(spot[3] == 'X' && spot[5] == 'X'){
            
            if(spot[6] == 'X'){
                if(cpuChoicesContains('7') && cpuChoicesContains('9')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(cpuChoicesContains('4') && cpuChoicesContains('9')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('9') && cpuChoicesContains('7')){
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('2')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
            }
        }
        
        //Spots 3 & 6 taken first
        
        else if(spot[3] == 'X' && spot[6] == 'X'){
            
            if(spot[7] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
                
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
            }
        }


        //Spots 3 & 7 taken first
        
        else if(spot[3] == 'X' && spot[7] == 'X'){
            
            if(spot[8] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
            }
        }


        //Spots 3 & 8 taken first
        
        else if(spot[3] == 'X' && spot[8] == 'X'){
            
            if(spot[9] == 'X'){
                if(cpuChoicesContains('5') && cpuChoicesContains('6')){
                    spot[4] = 'O';
                    cpuChoices[2] = '4';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('7')){
                    spot[4] = 'O';
                    cpuChoices[2] = '4';
                }
            }
        }


        //Spots 4 & 5 taken first
        
        else if(spot[4] == 'X' && spot[5] == 'X'){
            
            if(spot[7] == 'X'){
                if(cpuChoicesContains('9') && cpuChoicesContains('6')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
                else if(cpuChoicesContains('3') && cpuChoicesContains('9')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('2') && cpuChoicesContains('9')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('6')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
            }
        }
        
        //Spots 4 & 6 taken first
        
        else if(spot[4] == 'X' && spot[6] == 'X'){
            
            if(spot[7] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
                
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('3') && cpuChoicesContains('5')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('1')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
            }
        }
        
        //Spots 4 & 7 taken first
        
        else if(spot[4] == 'X' && spot[7] == 'X'){
            
            if(spot[8] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[9] = 'O';
                    cpuChoices[2] = '9';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('7')){
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
                
            }
        }


        //Spots 4 & 8 taken first
        
        else if(spot[4] == 'X' && spot[8] == 'X'){
            
            if(spot[9] == 'X'){
                if(cpuChoicesContains('3') && cpuChoicesContains('5')){
                    spot[7] = 'O';
                    cpuChoices[2] = '7';
                }
            }
        }
        
        //Spots 5 & 6 taken first
        
        if(spot[5] == 'X' && spot[6] == 'X'){
            
            if(spot[7] == 'X'){
                if(cpuChoicesContains('4') && cpuChoicesContains('9')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
                
                else if(cpuChoicesContains('3') && cpuChoicesContains('9')){
                    spot[4] = 'O';
                    cpuChoices[2] = '4';
                }
            }
            
            else if(spot[8] == 'X'){
                if(cpuChoicesContains('4') && cpuChoicesContains('9')){
                    spot[2] = 'O';
                    cpuChoices[2] = '2';
                }
                
                else if(cpuChoicesContains('9') && cpuChoicesContains('5')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
                
                else if(cpuChoicesContains('2') && cpuChoicesContains('9')){
                    spot[4] = 'O';
                    cpuChoices[2] = '4';
                }
                
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('1') && cpuChoicesContains('5')){
                    spot[3] = 'O';
                    cpuChoices[2] = '3';
                }
            }
        }
        
        //Spots 5 & 7 taken first
        
        if(spot[5] == 'X' && spot[7] == 'X'){
            
            if(spot[8] == 'X'){
                if(cpuChoicesContains('3') && cpuChoicesContains('9')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('3') && cpuChoicesContains('9')){
                    spot[6] = 'O';
                    cpuChoices[2] = '6';
                }
                
            }
        }
        
        //Spots 6 & 7 taken first

        if(spot[6] == 'X' && spot[7] == 'X'){
            
            if(spot[8] == 'X'){
                if(cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
            }
            
            else if(spot[9] == 'X'){
                if(cpuChoicesContains('3') && cpuChoicesContains('5')){
                    spot[8] = 'O';
                    cpuChoices[2] = '8';
                }
                
                else if(cpuChoicesContains('5') && cpuChoicesContains('9')){
                    spot[1] = 'O';
                    cpuChoices[2] = '1';
                }
                
            }
        }
    }
    
    //Fourth turn
    //AI will search for any possible 3 in a row by both bot & human, and complete that row
    if(round == 7){
        if((spot[1] == spot[2]) && spot[3] == '3'){
            spot[3] = 'O';
        }
        
        else if((spot[4] == spot[5]) && spot[6] == '6'){
            spot[6] = 'O';
        }
        
        else if((spot[7] == spot[8]) && spot[9] == '9'){
            spot[9] = 'O';
        }
        
        else if((spot[2] == spot[3]) && spot[1] == '1'){
            spot[1] = 'O';
        }
        
        else if((spot[5] == spot[6]) && spot[4] == '4'){
            spot[4] = 'O';
        }
        
        else if((spot[8] == spot[9]) && spot[7] == '7'){
            spot[7] = 'O';
        }
        
        else if((spot[1] == spot[3]) && spot[2] == '2'){
            spot[2] = 'O';
        }
        
        else if((spot[4] == spot[6]) && spot[5] == '5'){
            spot[5] = 'O';
        }
        
        else if((spot[7] == spot[9]) && spot[8] == '8'){
            spot[8] = 'O';
        }
        
        else if((spot[1] == spot[4]) && spot[7] == '7'){
            spot[7] = 'O';
        }
        
        else if((spot[2] == spot[5]) && spot[8] == '8'){
            spot[8] = 'O';
        }
        
        else if((spot[3] == spot[6]) && spot[9] == '9'){
            spot[9] = 'O';
        }
        
        else if((spot[1] == spot[7]) && spot[4] == '4'){
            spot[4] = 'O';
        }
        
        else if((spot[2] == spot[8]) && spot[5] == '5'){
            spot[5] = 'O';
        }
        
        else if((spot[3] == spot[9]) && spot[6] == '6'){
            spot[6] = 'O';
        }
        
        else if((spot[4] == spot[7]) && spot[1] == '1'){
            spot[1] = 'O';
        }
        
        else if((spot[5] == spot[8]) && spot[2] == '2'){
            spot[2] = 'O';
        }
        
        else if((spot[6] == spot[9]) && spot[3] == '3'){
            spot[3] = 'O';
        }
        
        else if((spot[1] == spot[5]) && spot[9] == '9'){
            spot[9] = 'O';
        }
        
        else if((spot[3] == spot[5]) && spot[7] == '7'){
            spot[7] = 'O';
        }
        
        else if((spot[1] == spot[9]) && spot[5] == '5'){
            spot[5] = 'O';
        }
        
        else if((spot[3] == spot[7]) && spot[5] == '5'){
            spot[5] = 'O';
        }
        
        else if((spot[5] == spot[9]) && spot[1] == '1'){
            spot[1] = 'O';
        }
        
        else if((spot[5] == spot[7]) && spot[3] == '3'){
            spot[3] = 'O';
        }
        
        //If no win is possible, AI will place marker in arbitrary posistion
        else{
            spot[findSpot()] = 'O';
        }
    }
    
    
    //Fifth turn
    //Exact same as 4th turn
    if(round == 9){
        if((spot[1] == spot[2]) && spot[3] == '3'){
            spot[3] = 'O';
        }
        
        else if((spot[4] == spot[5]) && spot[6] == '6'){
            spot[6] = 'O';
        }
        
        else if((spot[7] == spot[8]) && spot[9] == '9'){
            spot[9] = 'O';
        }
        
        else if((spot[2] == spot[3]) && spot[1] == '1'){
            spot[1] = 'O';
        }
        
        else if((spot[5] == spot[6]) && spot[4] == '4'){
            spot[4] = 'O';
        }
        
        else if((spot[8] == spot[9]) && spot[7] == '7'){
            spot[7] = 'O';
        }
        
        else if((spot[1] == spot[3]) && spot[2] == '2'){
            spot[2] = 'O';
        }
        
        else if((spot[4] == spot[6]) && spot[5] == '5'){
            spot[5] = 'O';
        }
        
        else if((spot[7] == spot[9]) && spot[8] == '8'){
            spot[8] = 'O';
        }
        
        else if((spot[1] == spot[4]) && spot[7] == '7'){
            spot[7] = 'O';
        }
        
        else if((spot[2] == spot[5]) && spot[8] == '8'){
            spot[8] = 'O';
        }
        
        else if((spot[3] == spot[6]) && spot[9] == '9'){
            spot[9] = 'O';
        }
        
        else if((spot[1] == spot[7]) && spot[4] == '4'){
            spot[4] = 'O';
        }
        
        else if((spot[2] == spot[8]) && spot[5] == '5'){
            spot[5] = 'O';
        }
        
        else if((spot[3] == spot[9]) && spot[6] == '6'){
            spot[6] = 'O';
        }
        
        else if((spot[4] == spot[7]) && spot[1] == '1'){
            spot[1] = 'O';
        }
        
        else if((spot[5] == spot[8]) && spot[2] == '2'){
            spot[2] = 'O';
        }
        
        else if((spot[6] == spot[9]) && spot[3] == '3'){
            spot[3] = 'O';
        }
        
        else if((spot[1] == spot[5]) && spot[9] == '9'){
            spot[9] = 'O';
        }
        
        else if((spot[3] == spot[5]) && spot[7] == '7'){
            spot[7] = 'O';
        }
        
        else if((spot[1] == spot[9]) && spot[5] == '5'){
            spot[5] = 'O';
        }
        
        else if((spot[3] == spot[7]) && spot[5] == '5'){
            spot[5] = 'O';
        }
        
        else if((spot[5] == spot[9]) && spot[1] == '1'){
            spot[1] = 'O';
        }
        
        else if((spot[5] == spot[7]) && spot[3] == '3'){
            spot[3] = 'O';
        }
        
        
        //If no win possible, AI will place marker in arbitrary posistion
        else{
            spot[findSpot()] = 'O';
        }
    }

}


//Method to clear the board & reset all values
void clearBoard(){

    spot[1] = '1';
    spot[2] = '2';
    spot[3] = '3';
    spot[4] = '4';
    spot[5] = '5';
    spot[6] = '6';
    spot[7] = '7';
    spot[8] = '8';
    spot[9] = '9';

}

//Clears Array of CPU choices
void clearCpu(){
    cpuChoices[0] = '0';
    cpuChoices[1] = '0';
    cpuChoices[2] = '0';
    cpuChoices[3] = '0';
    cpuChoices[4] = '0';
}


//Searches array of previous bot choices and returns true if bot has used that space
bool cpuChoicesContains(char value){
    for(int rep = 0; rep < 5; rep++){
        if(cpuChoices[rep] == value)
            return true;
    }
    
    return false;
}


//Will find a spot for bot to place piece, for likely game will result in draw
int findSpot(){
    
    if(spot[1] == '1') return 1;
    if(spot[2] == '2') return 2;
    if(spot[3] == '3') return 3;
    if(spot[4] == '4') return 4;
    if(spot[5] == '5') return 5;
    if(spot[6] == '6') return 6;
    if(spot[7] == '7') return 7;
    if(spot[8] == '8') return 8;
    if(spot[9] == '9') return 9;

    return 0;
}

 

Game Update: Tic Tac Toe AI

So over the past few weeks I have been working with Tic Tac Toe AI in an attempt integrate a bot into my Tic Tac Toe program, making it playable by just 1 person. The bot is coming along well, but through this process I have been reminded of the arduousness of creating AI. While the process has been incredibly fun, programming a bot to respond educatedly to every possible move made by a human is no small task. In addition to that, the bot must also take into account it’s own previous moves in order to construct the best, most likely to be successful, strategy.

To conquer this task I have been mapping every possible state of the tic tac toe board at every point of the game, taking into account the preset moves of the AI as well as every move that may be made by the human player. The mapping looks like this:IMG_1001

 

Using these notes I’m able to quickly assess which moves the bot should have programmed into itself, as well as which moves would never be necessary. For example, the bot will always try to go for the middle box (box 5) for it’s first move, but if that box is taken, it will default to the bottom right corner (box 9). Therefore, the bot will never encounter a situation in which the human player has both box 5 & box 9, so it does not need to have a response to that situation. While that is a very simple example, as the game progresses and the board becomes more complex, the number of situations which the bot could never face multiplies rapidly. Keeping track of these situations is crucial to creating clean, well organized code, as well as keeping the bot as efficient as possible. Below is some output from the unfinished bot. The bot should be finished and posted by early next week!Screen Shot 2018-03-29 at 2.49.41 PM

Game Sample: Converse Method

This is a method from a game I worked on. The method takes 6 strings, 1 representing a possible prompt, and then the others are possible responses, and returns the char selected by the user.

This method is used in my text based game to format dialogue, take a response, and return the letter answered. The method can be sent empty strings for answers which are not relevant, and will dispose of them, not allowing a user to pick them as an answer.

Screen Shot 2018-01-28 at 11.39.59 AMScreen Shot 2018-01-28 at 11.43.15 AM

char converse(string statement, string responseA, string responseB, string responseC, string responseD, string responseE){

    //char to be returned, representing answer. then sleeps to create pause
    char answer;
    sleep(3);

    //bools to represent that the letter chosen is valid
    bool answerB = false;
    bool answerC = false;
    bool answerD = false;
    bool answerE = false;

    //question posed
    cout << endl << endl << statement << endl << endl << endl;

    //possible responses
    cout << "A. " << responseA << endl;           //if there are multiple possible responses, this will trigger and set the corresponding bool to true. //B if(responseB.length() > 0){
        cout << "B. " << responseB << endl; answerB = true; } //C if(responseC.length() > 0){
        cout << "C. " << responseC << endl; answerC = true; } //D if(responseD.length() > 0){
        cout << "D. " << responseD << endl; answerD = true; } //E if(responseE.length() > 0){
        cout << "E. " << responseE << endl; answerE = true;     } //loop to allow user to make invalid entry while(true){ //stores user's answer in "answer" char cin >> answer;
        answer = tolower(answer);
//swtich statement to return user's response
        switch(answer){
            //if user answers:
            case 'a':
                return 'a';
                break;
            //if user answers:
            case 'b':
                if(answerB == true) return 'b';
                else break;
            //if user answers:
            case 'c':
                if(answerC == true) return 'c';
                else break;
            //if user answers:
            case 'd':
                if(answerD == true) return 'd';
                else break;
            //if user answers:
            case 'e':
                if(answerE == true) return 'e';
                else break;
            //otherwise, loop again
            default:
                break;
        }

        cout << "INVALID RESPONSE. Please choose a valid response" <<span 				data-mce-type="bookmark" 				id="mce_SELREST_start" 				data-mce-style="overflow:hidden;line-height:0" 				style="overflow:hidden;line-height:0" 			></span>< endl;
    }
}
</pre>