International Research Journal of Modernization in Engineering Technology and Science
( Peer-Reviewed, Open Access, Fully Refereed International Journal ) Volume:05/Issue:04/April-2023 Impact Factor- 7.868 www.irjmets.com
TIC TAC TOE USING AI
Hrishikesh Patil*1, Dhruvesh Gangapuram*2, Prayag Sawant*3, Hrishikesh Phanase*4 *1,2,3,4Student, Computer Engineering, Rajendra Mane College Of Engineering And Technology Sangmeshwar, Maharashtra, India. DOI : https://www.doi.org/10.56726/IRJMETS35839 ABSTRACT This project seeks to develop a Tic Tac Toe game with AI and multiplayer features. The game's AI is built on the mini-max algorithm, which allows the computer to make the best plays based on the current state of the game. The multiplayer mode allows two players to compete against one other through a network, with the option of playing locally or remotely. The game was created with Python and Pygame, and it features an easy and user- friendly interface, numerous difficulty levels, and support for multiple concurrent connections. Keywords: Mini-Max Algorithm, Pygame, User-Friendly Interface, Multiple Concurrent Connections. I. INTRODUCTION Tic Tac Toe is a popular game that is simple to learn and play. Yet, because to the restricted number of viable moves, it might become predictable and boring. As a result, incorporating an AI method such as the minimax theorem might increase the game's difficulty and excitement. Adding multiplayer capabilities to the game also makes it more intriguing by allowing players to compete against one another. This project combines AI and multiplayer features to produce a hard and engaging Tic Tac Toe game. The AI component of the game employs the min-max algorithm to allow the computer to make optimum movements, and the multiplayer component allows players to compete against one another via a network. Python and Pygame were used to create the game, which has a user-friendly interface, varied difficulty levels, and support for multiple simultaneous connections. Overall, the mix of AI and multiplayer features improves on the basic Tic Tac Toe game, making it more engaging and interesting for players. This project incorporates several elements that improve the overall gameplay experience, in addition to the implementation of the min-max algorithm and multiplayer capabilities. The user interface, for example, is intended to be visually appealing and simple to use, with clear images and straightforward controls. The installation of several difficulty levels for the AI is a crucial part of this project. The player may select between numerous difficulty levels, ranging from simple to challenging. This allows players of all skill levels, from beginners to experienced, to enjoy the game. The AI is also meant to be flexible, altering its difficulty level dependent on the performance of the user. The installation of the multiplayer component is another critical feature of the project. Participants can compete in real-time by connecting to each other over a network, either locally or remotely. Several simultaneous connections are supported by the game, allowing numerous players to compete against each other at the same time. Overall, this project blends powerful AI algorithms with multiplayer capability to produce a pleasant Tic Tac Toe game. The game is suited for players of all skill levels due to its user-friendly interface, numerous difficulty levels, and support for multiple simultaneous connections. II. METHODOLOGY a. Artificial Intelligence The minimax search method is a depth-first, depth-limited search method. The goal is to begin at the present location and utilize the plausible-move generator to build a collection of possible successor positions. We can now apply the static evaluation function to those positions and pick the best one. Doing so, we can represent the evaluation by backing up the staring position. The starting position is precisely as advantageous to us as the position produced by the best move we can make next. In this case, we suppose that the static evaluation
www.irjmets.com @International Research Journal of Modernization in Engineering, Technology and Science
[1600] e-ISSN: 2582-5208 International Research Journal of Modernization in Engineering Technology and Science ( Peer-Reviewed, Open Access, Fully Refereed International Journal ) Volume:05/Issue:04/April-2023 Impact Factor- 7.868 www.irjmets.com function returns a large result, indicating that we are in a positive condition. Therefore, our aim is to increase the value of the next board position's static evaluation function. The implementation of this algorithm can be done in two ways, one of which is using random function and other can deciding using the heuristic value. Typically, first move is decide using random function but it would be computationally expensive as the game tree is quite large at the beginning of the game. It better to choose the heuristic way. The common heuristic way is to start at the centre of the board, it gives more possible ways to win. By playing at the centre there can be four possible way to win. Another approach is to play at the corner as it gives more strategic advantage to the player. But playing at the corner can be riskier as it gives more opportunities to block the player’s move. Below you will find the representation of both the heuristic way.
Fig. 1. Fig. 1.2 Fig. 1.3 Fig. 1.4
b. Multiplayer mode The multiplayer paradigm splits communicating programs into two major types when used in multiplayer mode. A program called a server watch for incoming communication requests from clients. After receiving a client request, the server carries out the required calculations and sends the outcome back to the client. UDP communication between the client and server is connectionless, whereas TCP communication is connection- oriented. Steps: 1. Find the IP address and protocol port number of the server with which communication is desired. 2. Allocate a socket. 3. Specify that the connection needs an arbitrary, unused protocol port on the local machine, and allow the TCP to choose one. 4. Connect the socket to the server. 5. Communicate with the server using the application-level protocol(this usually involves sending requests and awaiting replies). 6. Close the connection.
www.irjmets.com @International Research Journal of Modernization in Engineering, Technology and Science
[1601] e-ISSN: 2582-5208 International Research Journal of Modernization in Engineering Technology and Science ( Peer-Reviewed, Open Access, Fully Refereed International Journal ) Volume:05/Issue:04/April-2023 Impact Factor- 7.868 www.irjmets.com Server calls An application calls socket to create a new socket that may be used for network communication. The cell provides a descriptor for the newly generated socket. The call's arguments describe the protocol family that the program will use as well as the protocol or kind of service it requires. Connect calls To establish a live connection to a distant server, a client must first create a socket and then call connect. The client can provide the remote endpoint, which contains the remote machine's IP address and protocol port number, using an argument to connect. Clients can send and receive data once a connection has been established. Write calls The write command is used by both clients and servers to transport data across a TCP connection. Clients often use write to submit requests, while servers use it to provide answers. Read call To receive data from a TCP connection, the client and the server both utilise read. The server typically uses read to accept a request that the client submits by using write after the connection has been made. The client uses a read to get a response after sending a request. Close call After utilizing a socket, a client or server uses it close to deallocate it. The connection is instantly cut off and the socket is deallocated if just one process is utilizing it. When many processes share a socket, the reference count is decremented for each process, and the socket is deallocated when the reference count is zero. Bind calls When a socket is formed, neither the local nor the remote address is assigned, therefore it has no idea of the endpoint addresses. To define the local end point address for a socket, an application uses the bind function. An end point address and a socket descriptor are required inputs for the call. The endpoint address for TCP/IP protocols employs a structure called sockaddr_in that contains both an IP address and a protocol port number. Servers often use bind to provide the popular port at which they will listen for connections. Listen calls Since neither the local nor the remote address is assigned when the socket is formed, it has no idea of the endpoint addresses. In order to define the local endpoint address for a socket, an application calls bind. A socket descriptor and endpoint address are specified as parameters to the call. The sockaddr_in structure, which contains both an IP address and a protocol port number, is used as the endpoint address for TCP/IP communications. In order to wait for connections, servers often utilize bind to provide the well-known port. Accept calls For TCP sockets, the server calls accept to get the subsequent incoming connection request after calling socket to build the socket, bind to define a local end point address, and listen to put the socket in passive mode. The socket from which a connection should be accepted is specified via an argument to accept. For each new connection request, accept establishes a new socket and gives its caller the descriptor of the new socket. The server utilises the new socket exclusively for the new connection it uses the original socket to accept further connection requests. The server can transport data on a new socket after accepting a connection. The server closes the new socket when it has finished utilising it.
Client server connection over a PAN network
www.irjmets.com @International Research Journal of Modernization in Engineering, Technology and Science
[1602] e-ISSN: 2582-5208 International Research Journal of Modernization in Engineering Technology and Science ( Peer-Reviewed, Open Access, Fully Refereed International Journal ) Volume:05/Issue:04/April-2023 Impact Factor- 7.868 www.irjmets.com II. CONCLUSION Finally, this project on the Tic Tac Toe game integrating AI and multiplayer features was created to give players an exciting and demanding gaming experience. The AI component's usage of the min-max algorithm assures that players will face a challenging opponent capable of making optimum plays. At the same time, multiplayer features allow players to compete against each other in real-time. The user interface of the game has been created to be intuitive and user-friendly, with elements such as sound effects and animations that improve the entire gameplay experience. Furthermore, the use of several difficulty levels for the AI assures that players of all skill levels may enjoy the game. Overall, this work contributes significantly to the development of AI-based gaming applications and has the potential to encourage more research and development in this sector. By including AI and multiplayer elements, this project gives a fresh and engaging way to play the classic Tic Tac Toe game. III. REFERENCE [1] Elaine Rich, Kevin Knight, Shivashankar B Nair (Third Edition) “Artificial Intelligence”, McGrew Hill. [2] Ashutosh Kumar Sahu, Parthasarathi Palita, Anupam Mohanty,”Tic tac toe game between computers: a computational intelligence approach” on siksha O’ Anusandhan university, 20 May 2018. [3] K. Yeung, B. Jacques, R. Du,”Playing tic-tac-toe with robot on the web in real time”, on international Conference on Engineering Education, 18 August 2022 [4] Sneha Garg, Dalpat Songara, Saurabh Maheshwari,” The Winning Strategy of Tic Tac Toe Game Model by using Theoretical Computer Science”, 2017 International Conference on Computer, Communication and Electronic (comptelix), Manipal university Jaipur, 01 February 2017 [5] Douglas E. Comer, David L. Stevens, (Second Edition, Vol. III),”Internet working with TCP/IP” , Prentice- Hall of India Private Limited.
www.irjmets.com @International Research Journal of Modernization in Engineering, Technology and Science
ChatGPT Side Hustles 2024 - Unlock the Digital Goldmine and Get AI Working for You Fast with More Than 85 Side Hustle Ideas to Boost Passive Income, Create New Cash Flow, and Get Ahead of the Curve
ChatGPT Millionaire 2024 - Bot-Driven Side Hustles, Prompt Engineering Shortcut Secrets, and Automated Income Streams that Print Money While You Sleep. The Ultimate Beginner’s Guide for AI Business
ChatGPT Money Machine 2024 - The Ultimate Chatbot Cheat Sheet to Go From Clueless Noob to Prompt Prodigy Fast! Complete AI Beginner’s Course to Catch the GPT Gold Rush Before It Leaves You Behind