Skip to content

Instantly share code, notes, and snippets.

View HunterVL's full-sized avatar

Hunter Vander Linden HunterVL

View GitHub Profile
void beep(String letter){
//Beeps letter
for (int index = 0; index < letter.length(); index++){
//Figures out if char is dot or dash and turns it on and off with varying delay.
switch (letter[index]) {
case '.':
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
break;
#define compareBoxes(box1, box2, box3) ((board[box1] == board[box2]) && (board[box2] == board[box3]) && (board[box1] != 0)) //Checkes if three items are the same, and makes sure they're not 0's.
#define numberToLetter(x) ((x > 0) ? (x == 1) ? 'X' : 'O' : ' ') //Takes the number and turns it into the letter or space.
int getWinner(int board[9]) {
//Finds winner of game, if there is no winner, returns 0.
int winner = 0;
for (int x = 0; x < 3; x++) {
if (compareBoxes(3*x, 3*x+1, 3*x+2)) { //Chekcs rows.
winner = board[3*x];
break;
@HunterVL
HunterVL / Tic-Tac-Toe.cpp
Created December 21, 2016 05:26
A C++ bot that plays Tic-Tac-Toe against a human.
#include <iostream>
#include <cstring>
#include <algorithm>
#include <ctime>
using namespace std;
#define compareBoxes(box1, box2, box3) ((board[box1] == board[box2]) && (board[box2] == board[box3]) && (board[box1] != 0)) //Checkes if three items are the same, and makes sure they're not 0's.
#define numberToLetter(x) ((x > 0) ? (x == 1) ? 'X' : 'O' : ' ') //Takes the number and turns it into the letter or space.