This is a tic-tac-toe game but differs from most others as it carries the option of playing against an AI (COM) or against a friend.

Overview

TIC-TAC-TOE

This is a simple tic-tac-toe game with the exception of playing against an algorithm or against a friend.
At the very start, you have to select your marker X or O. Note: X goes first.
You can simply play by clicking on an empty spot when it's your turn.
If you've clicked on 3 consecutive spots for any horizontal, vertical or diagonal spots, you win!

Contributing to this project

You are welcome to contribute to this project. Please create a different branch for your contribution describing the feature or bug you want to fix, for example fixes-comai-algorithm and then create a PR. Thank you.

Installation

Please run the following commands

  • Install dependencies

npm install

  • Launch localhost to preview application

npm run start

  • Compile code for production deployment

npm run build

Appreciation

Thank you for taking you time on this project. If you come across any bug, please raise an issue for it so that others can help solve it. Also if you have an idea on how to fix an issue, please go ahead to make a PR.
Thank you!

Made with 💜 by Narudesigns

You might also like...

🐶 Learn JS Promises, with your friend 👑 Princess!

🐶 Learn JS Promises, with your friend 👑 Princess!

Jun 9, 2022

Friend Finder App, asks questions and recommends friends

Friendology Friend Finder app created as a Course Project for CS-522 Social Computing, at IIT Ropar. The application asks questions regarding lifestyl

Apr 26, 2022

Crawl WeChat Moments and visualize friend interactions.

请注意:微信朋友圈内容可能涉及隐私,如果要使用本爬虫进行个人研究以外的其他活动,请仔细考虑可能带来的社会影响与法律后果。 使用方法: 配环境。 conda create -n friends conda activate friends conda install psutil conda inst

Nov 24, 2022

In 2012 the King of Spain, Juan Carlos I, transferred 65 million euros to a friend from a secret account in Switzerland. What lies actually behind this rare donation? This repository contains the full source code of the website ladonacion.es.

La Donación full source code and documentation This documentation draft is a work in progress. I expect to have it completed by September 24, 2022. ⭐

Dec 24, 2022

Add Your Skill & Find Your Developer Friend

Add Your Skill & Find Your Developer Friend! Want to contribute to this project? 📌 Tech Stack html css nextjs tailwind Contributing Pull requests are

Nov 17, 2022

Fullstack Dynamic NFT Mini Game built using 💎 Diamond Standard [EIP 2535] 🏃‍♀️Players can use Hero NFT to battle against Thanos ⚔ Heroes can be Healed by staking their NFT 🛡

Fullstack Dynamic NFT Mini Game built using 💎 Diamond Standard [EIP 2535]  🏃‍♀️Players can use Hero NFT to battle against Thanos ⚔ Heroes can be Healed by staking their NFT 🛡

💎 Fullstack Dynamic NFT Mini Game 🎮 💎 Using Diamond Standard Play On 💎 🎮 ⏩ http://diamond-dapp.vercel.app/ Project Description 📝 Fullstack Dynam

Dec 23, 2022

A server setup to take screenshots against the green screen in-game.

alt:V Clothing Green Screener Support on Patreon. Seriously. Ever want screenshots of every single clothing item in GTA:V? Well this is your repositor

Dec 26, 2022

Cards Against Humanity Game Client made with ⚡Nextron (Next.js + Electron) and Typescript

CAH Client Introduction This project is one of the other projects related to the Cards Against Humanity (CAH) game. This client is made in Electron, u

Jun 17, 2022
Comments
  • fix: AI playing twice when AI marker is X

    fix: AI playing twice when AI marker is X

    // Check if human is playing against com
      useEffect(() => {
        if (opponent === 'COM' && !turn) comAi(turn, boardState, rules, handleClick, roundIsCompleted);
      }, [turn]);
    
      // play and allow next turn
      useEffect(() => {
        let isMounted = true;
        // check if all spots has some value but no winner, game result is a tie 
        if (isMounted && (winPattern.length < 1) && (boardState.every(spot => spot !== ''))) {
          setTies(prevState => prevState + 1);
          setFinalResult("It's a tie");
          resetGame();
        } else if (isMounted && boardState.some(spot => spot !== '')) play(); // next player's turn
        return () => {
          isMounted = false;
          clearTimeout(timeout);
        }
      }, [boardState]);
    
    

    When Game.js mounts, following how the useEffects are called, the comAI plays and the "else if" statement in the second useEffect will evaluate to false which won't call the play() function that toggles the turn value. But comAi will cause boardState to update through the handleClick() function which will in effect cause a rerender of the component and since turn is still false, comAi will play again. By this second rerender, the "else if" statement in the second useEffect will evaluate to true which then calls the play() function.

    so switching the order of the useEffects like below solved the issue

      // play and allow next turn
      useEffect(() => {
        let isMounted = true;
        // check if all spots has some value but no winner, game result is a tie 
        if (isMounted && (winPattern.length < 1) && (boardState.every(spot => spot !== ''))) {
          setTies(prevState => prevState + 1);
          setFinalResult("It's a tie");
          resetGame();
        } else if (isMounted && boardState.some(spot => spot !== '')) play(); // next player's turn
        return () => {
          isMounted = false;
          clearTimeout(timeout);
        }
      }, [boardState]);
    
    
    // Check if human is playing against com
      useEffect(() => {
        if (opponent === 'COM' && !turn) comAi(turn, boardState, rules, handleClick, roundIsCompleted);
      }, [turn]);
    
    
    
    
    opened by kcde 7
  • COM AI plays twice at the start of the game if it goes first

    COM AI plays twice at the start of the game if it goes first

    The Problem

    The AI plays twice when I select the O marker (which makes it play first as X goes first). This might be a rendering issue.

    Steps to Reproduce Issue

    • Select O marker
    • Select COM as the opponent
    • Click the START button to launch the game

    See screenshots: Screenshot 2022-04-10 at 10 49 11 AM


    Screenshot 2022-04-10 at 10 49 22 AM
    opened by NARUDESIGNS 2
Owner
Paul Ibeabuchi C.
Frontend Developer | UI Designer | Graphics Designer. Javascript Enthusiast 😎
Paul Ibeabuchi C.
Tic Tac Toe game (HTML, CSS and JS)

Tic-Tac-Toe Tic Tac Toe game built as a site written with HTML, CSS and JS. Authors @Sh1Sh0p FAQ Does the game have a multiplayer option? No. Does the

Sh1Sh0 5 Oct 25, 2022
🤖A Tic-Tac-Toe solver that uses the minimax algorithm and alpha-beta pruning to make it unbeatable

Tic-Tac-Toe AI A Tic-Tac-Toe solver that uses the minimax algorithm and alpha-beta pruning to make it unbeatable How it Works Tic-Tac-Toe is what is k

Martin 4 May 20, 2022
👨🏼‍🎨 It is a virtual blackboard, where you can make 🖌 drawings through 🖱 the mouse. You have the option to choose 🎨 colors and line thickness.

????‍?? Lets Draw ?? ÍNDICE 1. Lets-Draw 2. Realization of the Project 3. Technologies used 4. Authors 1. Lets-Draw ????‍?? It is a virtual blackboard

Rosamaria Rodriguez 2 Mar 7, 2022
A simple library to draw option menu or other popup inputs and layout on Node.js console.

console-gui-tools A simple library to draw option menu or other popup inputs and layout on Node.js console. console-gui-tools A simple Node.js library

Elia Lazzari 12 Dec 24, 2022
Rust's Option and Result, implemented for TypeScript.

oxide.ts Rust's Option<T> and Result<T, E>, implemented for TypeScript. Features Zero dependencies, full test coverage and examples for every function

null 331 Jan 3, 2023
El repositorio de cheatsheets de TIC. Pensado para que los alumnos puedan utilizar a la hora de programar como "ayudamemorias".

Cheatsheets de TIC Este es el repositorio de la web de cheatsheets de TIC. Para acceder a la web hacer click acá. ¿Cómo hago un cambio? ¿Mi cambio tie

null 37 Nov 10, 2022
Idle Game Based on A Dark Room with bits of NGU Idle and others mixed in.

An-Empty-World Main Story: You wake up in a strange place, surrounded by debris. Unaware of how you got there, it becomes immediately aware that you'r

Andre Schoolman 2 Mar 26, 2022
click your any waifu, or...... friend?

popwaifu Here is popwaifu.click backend project. Frontend project is on popwaifu-web run server Install Node.js I use 14.17.6 when writing this, recom

null 19 Feb 17, 2022