Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <random>
- #include <string>
- #include <vector>
- #include "ai.h"
- int FirstOpenAgent(int board[6][7], int ai_player) {
- // To keep the interface for AIs consistent.
- (void)ai_player;
- // Loop over board and find the first place that is not occupied.
- for (int row = 0; row < 5; ++row) {
- for (int col = 0; col < 6; ++col) {
- if (board[row][col] == 0) {
- return col;
- }
- }
- }
- // This can only happen if game is broken.
- throw;
- //return board[6][7];
- }
- int RandomAgent(int board[6][7], int ai_player) {
- // To keep the interface for AIs consistent.
- (void)ai_player;
- std::vector<int> open_columns;
- // Create list of columns that has an open space
- for (int row = 0; row < 6; ++row) {
- for (int col = 0; col < 7; ++col) {
- if (board[row][col] == 0) {
- open_columns.push_back(col);
- }
- }
- }
- // Randomly select from this list. An empty list implies the board is full.
- // This should not happen.
- //.empty()
- for (size_t choice : open_columns) {
- choice = rand() % open_columns.size();
- srand(choice);
- board[6][7] = {open_columns[choice]};
- // This is working. Ai is choosing from random columns. Feb 15
- return board[6][7];
- }
- /*if (open_columns.empty()) {
- throw; // IT was complaining about this! (Line 49)
- }*/
- return 0;
- }
- PlayerType GetPlayerType(const std::string &arg) {
- if (arg == "human") {
- return PlayerType::kHuman;
- } else if (arg == "random") {
- return PlayerType::kRandom;
- } else if (arg == "first") {
- return PlayerType::kFirst;
- } else {
- return PlayerType::kInvalid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment