smorga41 / connect-4-minimax-ai Goto Github PK
View Code? Open in Web Editor NEWAn Ai using the minimax algorithm to play a human at connect 4.
An Ai using the minimax algorithm to play a human at connect 4.
see attached my winning scenario.
scenario_connect4_won.txt
--
% python3 Connect4_Game.py
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
Player 1's Turn
select a column 1-7: 4
CONGRATULATIONS you played the best move for this scenario
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 0 0 0
Player 2's Turn
Ai is thinking with a depth of 6
MinMax Algorithm took 0.7464492321014404s to run at a depth of 6
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
The AI has played column 4
Player 1's Turn
select a column 1-7: 4
CONGRATULATIONS you played the best move for this scenario
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
Player 2's Turn
Ai is thinking with a depth of 6
MinMax Algorithm took 2.25075626373291s to run at a depth of 6
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
The AI has played column 4
Player 1's Turn
select a column 1-7: 4
That was not the best move
You should have played column 6
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
Player 2's Turn
Ai is thinking with a depth of 6
MinMax Algorithm took 2.8082640171051025s to run at a depth of 6
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 2 0 0
The AI has played column 5
Player 1's Turn
select a column 1-7: 2
That was not the best move
You should have played column 3
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 1 0 1 2 0 0
Player 2's Turn
Ai is thinking with a depth of 6
MinMax Algorithm took 1.6331062316894531s to run at a depth of 6
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
0 0 0 2 2 0 0
0 1 0 1 2 0 0
The AI has played column 5
Player 1's Turn
select a column 1-7: 2
That was not the best move
You should have played column 3
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
0 1 0 2 2 0 0
0 1 0 1 2 0 0
Player 2's Turn
Ai is thinking with a depth of 6
MinMax Algorithm took 1.3235938549041748s to run at a depth of 6
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 0 0 0
0 1 0 2 2 0 0
0 1 2 1 2 0 0
The AI has played column 3
Player 1's Turn
select a column 1-7: 5
CONGRATULATIONS you played the best move for this scenario
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 0 0 0
0 0 0 1 1 0 0
0 1 0 2 2 0 0
0 1 2 1 2 0 0
Player 2's Turn
Ai is thinking with a depth of 6
MinMax Algorithm took 1.6202051639556885s to run at a depth of 6
Depth increased to 7
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 2 0 0
0 0 0 1 1 0 0
0 1 0 2 2 0 0
0 1 2 1 2 0 0
The AI has played column 5
Player 1's Turn
select a column 1-7: 2
That was not the best move
You should have played column 5
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 2 2 0 0
0 1 0 1 1 0 0
0 1 0 2 2 0 0
0 1 2 1 2 0 0
Player 2's Turn
Ai is thinking with a depth of 7
MinMax Algorithm took 5.060753107070923s to run at a depth of 7
Depth increased to 8
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 2 0 2 2 0 0
0 1 0 1 1 0 0
0 1 0 2 2 0 0
0 1 2 1 2 0 0
The AI has played column 2
Player 1's Turn
select a column 1-7: 5
That was not the best move
You should have played column 4
0 0 0 0 0 0 0
0 0 0 1 1 0 0
0 2 0 2 2 0 0
0 1 0 1 1 0 0
0 1 0 2 2 0 0
0 1 2 1 2 0 0
Player 2's Turn
Ai is thinking with a depth of 8
MinMax Algorithm took 3.2922990322113037s to run at a depth of 8
Depth increased to 9
0 0 0 2 0 0 0
0 0 0 1 1 0 0
0 2 0 2 2 0 0
0 1 0 1 1 0 0
0 1 0 2 2 0 0
0 1 2 1 2 0 0
The AI has played column 4
Player 1's Turn
select a column 1-7: 1
That was not the best move
You should have played column 5
0 0 0 2 0 0 0
0 0 0 1 1 0 0
0 2 0 2 2 0 0
0 1 0 1 1 0 0
0 1 0 2 2 0 0
1 1 2 1 2 0 0
Player 2's Turn
Ai is thinking with a depth of 9
MinMax Algorithm took 7.416490077972412s to run at a depth of 9
Depth increased to 10
0 0 0 2 2 0 0
0 0 0 1 1 0 0
0 2 0 2 2 0 0
0 1 0 1 1 0 0
0 1 0 2 2 0 0
1 1 2 1 2 0 0
The AI has played column 5
Player 1's Turn
select a column 1-7: 2
That was not the best move
You should have played column 1
0 0 0 2 2 0 0
0 1 0 1 1 0 0
0 2 0 2 2 0 0
0 1 0 1 1 0 0
0 1 0 2 2 0 0
1 1 2 1 2 0 0
Player 2's Turn
Ai is thinking with a depth of 10
MinMax Algorithm took 7.351132154464722s to run at a depth of 10
Depth increased to 11
0 0 0 2 2 0 0
0 1 0 1 1 0 0
0 2 0 2 2 0 0
0 1 0 1 1 0 0
0 1 0 2 2 0 0
1 1 2 1 2 2 0
The AI has played column 6
Player 1's Turn
select a column 1-7: 6
CONGRATULATIONS you played the best move for this scenario
0 0 0 2 2 0 0
0 1 0 1 1 0 0
0 2 0 2 2 0 0
0 1 0 1 1 0 0
0 1 0 2 2 1 0
1 1 2 1 2 2 0
Player 2's Turn
Ai is thinking with a depth of 11
MinMax Algorithm took 23.145294189453125s to run at a depth of 11
Depth decreased to 10
0 0 0 2 2 0 0
0 1 0 1 1 0 0
0 2 0 2 2 0 0
0 1 0 1 1 2 0
0 1 0 2 2 1 0
1 1 2 1 2 2 0
The AI has played column 6
Player 1's Turn
select a column 1-7: 6
CONGRATULATIONS you played the best move for this scenario
0 0 0 2 2 0 0
0 1 0 1 1 0 0
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 1 0 2 2 1 0
1 1 2 1 2 2 0
Player 2's Turn
Ai is thinking with a depth of 10
MinMax Algorithm took 9.923530101776123s to run at a depth of 10
0 0 0 2 2 0 0
0 1 0 1 1 2 0
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 1 0 2 2 1 0
1 1 2 1 2 2 0
The AI has played column 6
Player 1's Turn
select a column 1-7: 6
That was not the best move
You should have played column 1
0 0 0 2 2 1 0
0 1 0 1 1 2 0
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 1 0 2 2 1 0
1 1 2 1 2 2 0
Player 2's Turn
Ai is thinking with a depth of 10
MinMax Algorithm took 1.342369556427002s to run at a depth of 10
Depth increased to 11
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 1 0 2 2 1 0
1 1 2 1 2 2 0
The AI has played column 2
Player 1's Turn
select a column 1-7: 7
That was not the best move
You should have played column 1
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 1 0 2 2 1 0
1 1 2 1 2 2 1
Player 2's Turn
Ai is thinking with a depth of 11
MinMax Algorithm took 0.06806206703186035s to run at a depth of 11
Depth increased to 12
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 1 0 2 2 1 2
1 1 2 1 2 2 1
The AI has played column 7
Player 1's Turn
select a column 1-7: 7
CONGRATULATIONS you played the best move for this scenario
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 2 0 2 2 1 0
0 1 0 1 1 2 1
0 1 0 2 2 1 2
1 1 2 1 2 2 1
Player 2's Turn
Ai is thinking with a depth of 12
MinMax Algorithm took 0.0269320011138916s to run at a depth of 12
Depth increased to 13
0 2 0 2 2 1 0
0 1 0 1 1 2 0
0 2 0 2 2 1 2
0 1 0 1 1 2 1
0 1 0 2 2 1 2
1 1 2 1 2 2 1
The AI has played column 7
Player 1's Turn
select a column 1-7: 7
CONGRATULATIONS you played the best move for this scenario
0 2 0 2 2 1 0
0 1 0 1 1 2 1
0 2 0 2 2 1 2
0 1 0 1 1 2 1
0 1 0 2 2 1 2
1 1 2 1 2 2 1
Player 2's Turn
Ai is thinking with a depth of 13
MinMax Algorithm took 0.011472225189208984s to run at a depth of 13
Depth increased to 14
0 2 0 2 2 1 2
0 1 0 1 1 2 1
0 2 0 2 2 1 2
0 1 0 1 1 2 1
0 1 0 2 2 1 2
1 1 2 1 2 2 1
The AI has played column 7
Player 1's Turn
select a column 1-7: 1
CONGRATULATIONS you played the best move for this scenario
0 2 0 2 2 1 2
0 1 0 1 1 2 1
0 2 0 2 2 1 2
0 1 0 1 1 2 1
1 1 0 2 2 1 2
1 1 2 1 2 2 1
Player 2's Turn
Ai is thinking with a depth of 14
MinMax Algorithm took 0.0053560733795166016s to run at a depth of 14
Depth increased to 15
0 2 0 2 2 1 2
0 1 0 1 1 2 1
0 2 0 2 2 1 2
2 1 0 1 1 2 1
1 1 0 2 2 1 2
1 1 2 1 2 2 1
The AI has played column 1
Player 1's Turn
select a column 1-7: 1
CONGRATULATIONS you played the best move for this scenario
0 2 0 2 2 1 2
0 1 0 1 1 2 1
1 2 0 2 2 1 2
2 1 0 1 1 2 1
1 1 0 2 2 1 2
1 1 2 1 2 2 1
Player 2's Turn
Ai is thinking with a depth of 15
MinMax Algorithm took 0.0022430419921875s to run at a depth of 15
Depth increased to 16
0 2 0 2 2 1 2
0 1 0 1 1 2 1
1 2 0 2 2 1 2
2 1 0 1 1 2 1
1 1 2 2 2 1 2
1 1 2 1 2 2 1
The AI has played column 3
Player 1's Turn
select a column 1-7: 3
CONGRATULATIONS you played the best move for this scenario
0 2 0 2 2 1 2
0 1 0 1 1 2 1
1 2 0 2 2 1 2
2 1 1 1 1 2 1
1 1 2 2 2 1 2
1 1 2 1 2 2 1
##############################
The Player has won
##############################
0 2 0 2 2 1 2
0 1 0 1 1 2 1
1 2 0 2 2 1 2
2 1 1 1 1 2 1
1 1 2 2 2 1 2
1 1 2 1 2 2 1
%
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.