Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Making a computer learn to play TicTacToe.

Background

As we talked about in class, you can write a program to play TicTacToe and which also learns strategy using MiniMax. As the program plays, it adds nodes to a game graph. The outcome of the games become the values (weights) of the end nodes. After each game, a MiniMax process (a double recursion you will write) is run to re-calculate all the weights. As the graph grows, the node weights will prevent the computer from following old losing paths. It will get to a point that you cannot beat it.

We do not implement any methods for playing. Well, that's not exactly true. We do assume that after a certain small number of games the computer would know to block the user if they already have 2 squares in a row and the third winning square has nothing in it. Similarly, we assume it would know to make a winning move if it had 2 squares in a row with the winning third square open when it is its turn to move. You can control when this knowledge appears by adjusting a const in the program called Early
(const int Early=3) near the beginning of the program. You can set Early to a high number and see that the computer will learn to block and notice winning moves, but it will take longer.

Your task(s)

The program is moderately large. To get into it, load the project TicTacToe2.vcproj. The main program is too long to ask you to do the whole thing. I wrote it all for you (in a file tictactoetemplate.cpp) except for the part that updates the graph weights after each run. There is a function in the program: void UpdateTree() that you need to fill out using the double recursion we discussed in class. I've also included a skeleton for 2 other functions you'll need, Min and Max. Without these doing minimax, the program plays but does not learn. So this is your end task. Write the needed functions. (They are quite short if you do it correctly.) But you also need to do a few other things.

It is not easy to test your work and to sort out how to integrate it with all the date structures and variables in the program. So I am posting (in the zip file) 2 other files that you must work with to get your code working. First, there is a node file (called nodesteatin.dat that has a "fake" set of 23 nodes. Your tasks are:

1. On paper, draw the tree/graph for this file (circles as nodes and lines from parents to children). The board positions in the nodes are real. The weights are not what would be in the real game, but they are good for testing. One node has 2 parents. The game starts with Min's move. Turn in your diagram.

2. Testing an algorithm inside a complex program can be hard. Often we write a "stub" program that just runs a new algorithm to test whether it works, but doesn't do the whold main program. You will complete such a test stub program in this part. Complete the test program I've posted in the zip file called updatenodestesttemplate.cpp. It does only 3 things. It reads the node value into the 2 dimensional array Tree[1500][19]. It then runs UpdateTree(), and it writes the updates tree (after minimax) to another file. So write your own UpdateTree and other needed functions here. Test your program and see that you get what you worked out on paper. (Note that in order to make writing and testing of this program easier, the input and output files are different so you do not overwrite the input file after the run. The main big program uses the same file for input and output so that you can run a session of 20 games, for example, and then another session of 30 games and the learning just goes on.)

3. Copy your functions into the main program and run it. Note that the main program has another constant you must adjust. It determines whether you will start and build a brand new nodes file or continue with a previous one. If you set const int GameCount = 0; then it will start over even if you have a nodes file. If you set the value to anything else, it will load the file named nodes.dat and continue with it and write its results to it when you finish.

Things to turn in:

1. Your diagnostic program.

2. Your main program and your final nodes.dat file.

3. On paper, turn in your graph of the 23 nodes including the weights and the board condition for each node.

Optional

Do you wonder what happens when the program is trained? I'm also enclosing two files called nodes400.dat and nodes500.dat. The numbers indicate the number of games played in each case to build that "brain." I can beat nodes400, but I can't beat nodes500. See if you can for fun. To run either, make a copy of it (to not mess up the original) and change its name to nodes.dat and run your main program.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91529848
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Subject computer algorithmsbook introduction to algorithms

Subject : Computer Algorithms Book: Introduction to Algorithms 3rd edition 1) a) Using Figure 10.1 as a model, illustrate the result of each operation in the sequence PUSH(S,6), PUSH(S,2), PUSH(S,8), POP(S), PUSH(S,5), P ...

Systems analysis projectpersonal trainer inc owns and

Systems analysis project Personal Trainer, Inc. owns and operates fitness centers in a dozen Midwestern cities. The centers have done well, and the company is planning an international expansion by opening a new "superce ...

Reminder all files must be closed when you are done with

Reminder: All files must be closed when you are done with them, even if it stops early due to an IOError. If you're using with, this will happen automatically. If you're trying to close things manually using .close(), th ...

At a certain temperature this reaction establishes an

At a certain temperature, this reaction establishes an equilibrium with the given equilibrium constant, Kc. Kc = 1.53 * 10^21 3A (g) + 2B (g) ------> 4C(g) If, at this temperature, 1.50 mol of A and 4.00 mol of B are pla ...

Whats the difference between a bigfile tablespace and a

What's the difference between a Bigfile tablespace and a Smallfile tablespace? Explain which you would use for your database and why.

How to design a java program that reads a sentence say s

How to design a Java program that reads a sentence, say s, consisting of lower-case words with .nextLine() method, identifies the words using .indexOf() and .substring() methods and saves them in String variables. Then t ...

Discuss the relationship between fundamental analysis and

Discuss the relationship between fundamental analysis and intrinsic value. Include real-world examples in your explanation.

Suppose that you are given a sorted list of n elements

Suppose that you are given a sorted list of n elements followed by f(n) randomly ordered elements. How would you sort the entire list if a. f(n) = 2? b. f(n) = vn? c. How large can f(n) be for the entire list to be sorte ...

Why are we in the golden age of technology entrepreneurship

Why are we in the 'golden age' of technology entrepreneurship? What factors are helping entrepreneurs more rapidly achieve their vision, and with a lower cost?

Question 1 describe and explain the role and function of

Question: 1. Describe and explain the role and function of network connectivity in current computing. 2. Describe and explain the protocols and interactions that implement network communications. 3. Describe and explain ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As