build: different location for clang release libs on UNIX
This change fixes the clang cmake config to use release libs of clang, adds the TicTacToe source files to bin/app/src/ and adds time measuring to the parse call in Project.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#ifndef _ARTIFICIAL_
|
||||
#define _ARTIFICIAL_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "player.h"
|
||||
|
||||
class ArtificialPlayer : public Player {
|
||||
public:
|
||||
ArtificialPlayer( Field::Token token, const std::string& name )
|
||||
: Player( token, name ) {
|
||||
}
|
||||
virtual ~ArtificialPlayer() {}
|
||||
|
||||
virtual Field::Move Turn( const Field& field ) const {
|
||||
// srand( static_cast<unsigned int>( time( NULL ) ) );
|
||||
Field fakeField = field.Clone();
|
||||
Node node = MinMax( fakeField, token_ );
|
||||
return node.move;
|
||||
}
|
||||
|
||||
private:
|
||||
struct Node {
|
||||
Field::Move move;
|
||||
int value;
|
||||
};
|
||||
|
||||
Node MinMax( Field& field, Field::Token token ) const {
|
||||
Node node;
|
||||
node.value = -10000;
|
||||
|
||||
Field::Move move;
|
||||
int sameMove;
|
||||
|
||||
for ( int i = 0; i < 3; i++ ) {
|
||||
move.row = i;
|
||||
|
||||
for ( int j = 0; j < 3; j++ ) {
|
||||
move.col = j;
|
||||
|
||||
if ( !field.IsEmpty( move ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
field.MakeMove( move, token );
|
||||
|
||||
int turnValue = Evaluate( field, token );
|
||||
if ( !turnValue && !field.IsFull() ) {
|
||||
turnValue = -MinMax( field, Field::Opponent( token ) ).value;
|
||||
}
|
||||
|
||||
field.ClearMove( move );
|
||||
|
||||
if ( turnValue > node.value ) {
|
||||
node.move = move;
|
||||
node.value = turnValue;
|
||||
sameMove = 1;
|
||||
} else if ( turnValue == node.value ) {
|
||||
sameMove++;
|
||||
if ( 1 % sameMove == 0 ) {
|
||||
node.move = move;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
int Evaluate( const Field& field, Field::Token token ) const {
|
||||
if ( field.SameInRow( token, 3 ) ) {
|
||||
return 2;
|
||||
} else if ( field.SameInRow( Field::Opponent( token ), 2 ) ) {
|
||||
return -1;
|
||||
} else if ( field.SameInRow( token, 2 ) > 1 ) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _ARTIFICIAL_
|
||||
Reference in New Issue
Block a user