-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.cpp
More file actions
73 lines (64 loc) · 1.55 KB
/
Copy pathBoard.cpp
File metadata and controls
73 lines (64 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Board.cpp
// SerpientesEscaleras
//
// Created by Rosa Guadalupe Paredes Juarez on 18/05/20.
// Copyright © 2020 Rosa Paredes. All rights reserved.
//
#include <stdio.h>
#include <cstdlib>
#include "Board.h"
#include "Tile.h"
#include "SnakeTile.h"
#include "LadderTile.h"
Board::Board() {
numberOfTiles = 30;
numberOfSnakes = 3;
numberOfLadders = 3;
penalty = -3;
reward = 3;
initialize();
}
Board::Board(int n, int s, int l, int p, int r) {
numberOfTiles = n;
numberOfSnakes = s;
numberOfLadders = l;
penalty = p;
reward = r;
initialize();
}
void Board::initialize() {
//LE AGREGUE ESTE +7 Porque habia un error al regresar una casilla que no existìa
tiles = vector<Tile>(numberOfTiles+7);
int snakes = 0;
int ladders = 0;
while(snakes < numberOfSnakes) {
int index = (rand() % numberOfTiles);
if(tiles[index].getType() == 'N') {
tiles[index] = SnakeTile(penalty);
snakes++;
}
}
while(ladders < numberOfSnakes) {
int index = (rand() % numberOfTiles);
if(tiles[index].getType() == 'N') {
tiles[index] = LadderTile(reward);
ladders++;
}
}
}
string Board::draw(){
string brd = "";
for (Tile t : tiles) {
char c = t.getType();
brd += c; // brd = brd + c;
brd += " "; // brd = brd + " ";
}
return brd;
}
char Board::getTile(int index) {
return tiles[index].getType();
}
int Board::getValue(int index) {
return tiles[index].getValue();
}