Upload files to "/"
This commit is contained in:
parent
517718e657
commit
d6c8d3a03a
37
scores.h
Normal file
37
scores.h
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by pranshav on 11/18/24.
|
||||
//
|
||||
|
||||
#ifndef SCORES_H
|
||||
#define SCORES_H
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
struct ScoreNode {
|
||||
char player;
|
||||
int score;
|
||||
};
|
||||
|
||||
class Scores {
|
||||
private:
|
||||
ScoreNode* array = nullptr;
|
||||
int size;
|
||||
int capacity;
|
||||
|
||||
private:
|
||||
void growArray();
|
||||
|
||||
public:
|
||||
Scores();
|
||||
|
||||
~Scores();
|
||||
|
||||
void addScore(char player);
|
||||
|
||||
void updateScore(char player);
|
||||
|
||||
ScoreNode findPlayerScore(char player);
|
||||
|
||||
void printResults();
|
||||
|
||||
};
|
||||
#endif //SCORES_H
|
79
strategicplayer.cxx
Normal file
79
strategicplayer.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
//
|
||||
// Created by pranshav on 11/18/24.
|
||||
//
|
||||
|
||||
#include "strategicplayer.h"
|
||||
|
||||
StrategicPlayer::StrategicPlayer() {}
|
||||
|
||||
StrategicPlayer::~StrategicPlayer() {}
|
||||
|
||||
point StrategicPlayer::strategicMove(Board& board, Points &points) {
|
||||
point move;
|
||||
for (int i=1;i<board.rows;i+=2) {
|
||||
for (int j=1;j<board.cols;j+=2) {
|
||||
if(boxCount(board,i,j)==3) {
|
||||
if (board.board[i-1][j]==' ') {//Up
|
||||
move.x = i-1;
|
||||
move.y = j;
|
||||
return move;
|
||||
} else if (board.board[i+1][j]==' ') {//Down
|
||||
move.x = i+1;
|
||||
move.y = j;
|
||||
return move;
|
||||
} else if (board.board[i][j+1]==' ') {//Right
|
||||
move.x = i;
|
||||
move.y = j+1;
|
||||
return move;
|
||||
} else if (board.board[i][j-1]==' ') {
|
||||
move.x = i;
|
||||
move.y = j-1;
|
||||
return move;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i=1;i<board.rows;i+=2) {
|
||||
for (int j=1;j<board.cols;j+=2) {
|
||||
if(StrategicPlayer::boxCount(board,i,j)==1) {
|
||||
if (board.board[i-1][j]!=' ') {//Up
|
||||
move.x = i;
|
||||
move.y = j-1;
|
||||
return move;
|
||||
} else if (board.board[i+1][j]==' ') {//Down
|
||||
move.x = i;
|
||||
move.y = j+1;
|
||||
return move;
|
||||
} else if (board.board[i][j+1]==' ') {//Right
|
||||
move.x = i-1;
|
||||
move.y = j;
|
||||
return move;
|
||||
} else if (board.board[i][j-1]==' ') {//Left
|
||||
move.x = i+1;
|
||||
move.y = j;
|
||||
return move;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int size = points.getSize();
|
||||
|
||||
if (size != 0) {
|
||||
srand(time(0));
|
||||
int randomIndex = rand()%size;
|
||||
move = points.array[randomIndex];
|
||||
points.removeIndex(randomIndex);
|
||||
return move;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int boxCount(const Board& board, int x, int y) {
|
||||
int count = 0;
|
||||
if (board.board[x-1][y]!=' ') count++; //Up
|
||||
if (board.board[x+1][y]!=' ') count++; //Down
|
||||
if (board.board[x][y-1]!=' ') count++; //Left
|
||||
if (board.board[x][y+1]!=' ') count++; //Right
|
||||
return count;
|
||||
}
|
19
strategicplayer.h
Normal file
19
strategicplayer.h
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by pranshav on 11/18/24.
|
||||
//
|
||||
|
||||
#ifndef STRATEGICPLAYER_H
|
||||
#define STRATEGICPLAYER_H
|
||||
#include "points.h"
|
||||
#include "board.h"
|
||||
#include <iostream>
|
||||
|
||||
class StrategicPlayer {
|
||||
public:
|
||||
StrategicPlayer();
|
||||
~StrategicPlayer();
|
||||
point strategicMove(Board& board, Points& points);
|
||||
int boxCount(const Board& board, int x, int y) const;
|
||||
};
|
||||
|
||||
#endif //STRATEGICPLAYER_H
|
Loading…
Reference in New Issue
Block a user