Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
private int minimax(bool flag) { int max_val=-1000,min_val=1000; int i,j,value = 1; if(checkVictory(computer) == 1) { return 10; } else if(checkVictory(human) == 1) { return -10; } else if(isFull()== 1) { return 0; } int[] score = {1,1,1,1,1,1,1,1,1};//if score[i]=1 then it is empty for(i=0;i<9;i++) { if(oriBoard[i] == "*") { if(min_val>max_val) // reverse of pruning condition..... { if(flag == true) { oriBoard[i] = "X"; value = minimax(false); } else { oriBoard[i] = "O"; value = minimax(true); } oriBoard[i] = "*"; score[i] = value; } } } if(flag == true) { max_val = -1000; for(j=0;j<9;j++) { if(score[j] > max_val && score[j] != 1) { max_val = score[j]; bestMove = j; } } return max_val; } if(flag == false) { min_val = 1000; for(j=0;j<9;j++) { if(score[j] < min_val && score[j] != 1) { min_val = score[j]; bestMove = j; } } return min_val; } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)