SlideShare a Scribd company logo
1 of 12
Your task in this assignment is to implement a simplified
guessing game, hinted by a well-known plastic board game
called Battleship. The computer arranges ships on the grid
structure in which each ship occupies a number of consecutive
positions on the grid. Those ships are arranged either
horizontally or vertically. The number of positions for each ship
is determined by the type of the ship. The ship cannot overlap
and only one ship can occupy any given position in the grid.
You can play a real version on the web such as this to get an
idea. The version to realize in this assignment is simpler and a
one-man based game in which you are bombing those ships
generated by your computer. The next sample session will
illustrate the entire scheme:
There are 6 ships. Must bomb 18 places to destroy all...
<<Pacific Ocean>>
A B C D E F G H I J
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . . . . . . . . .
4 . . . . . . . . . .
5 . . . . . . . . . .
6 . . . . . . . . . .
7 . . . . . . . . . .
8 . . . . . . . . . .
9 . . . . . . . . . .
10 . . . . . . . . . .
Enter position, "show", "init" or "quit": 4 G
You missed :(
<<Pacific Ocean>>
A B C D E F G H I J
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . . . . . . . . .
4 . . . . . . - . . .
5 . . . . . . . . . .
6 . . . . . . . . . .
7 . . . . . . . . . .
8 . . . . . . . . . .
9 . . . . . . . . . .
10 . . . . . . . . . .
Enter position, "show", "init" or "quit": 8 b
You hit :)
<<Pacific Ocean>>
A B C D E F G H I J
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . . . . . . . . .
4 . . . . . . - . . .
5 . . . . . . . . . .
6 . . . . . . . . . .
7 . . . . . . . . . .
8 . @ . . . . . . . .
9 . . . . . . . . . .
10 . . . . . . . . . .
Enter position, "show", "init" or "quit": show
<<Pacific Ocean>>
A B C D E F G H I J
1 . * . . * * * . . .
2 . * . . . . . . . .
3 . * . . * . . . . .
4 . . . . * . - . . .
5 . . . . * . . . * *
6 . . . * * . . . . .
7 . * . * . . . . . .
8 . @ . * . . . . . .
9 . * . . . . . . . .
10 . * . . . . . . . .
Enter position, "show", "init" or "quit": 8 B
You bomed same place... You missed :(
<<Pacific Ocean>>
A B C D E F G H I J
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . . . . . . . . .
4 . . . . . . - . . .
5 . . . . . . . . . .
6 . . . . . . . . . .
7 . . . . . . . . . .
8 . @ . . . . . . . .
9 . . . . . . . . . .
10 . . . . . . . . . .
Enter position, "show", "init" or "quit": init
There are 6 ships. Must bomb 18 places to destroy all...
<<Pacific Ocean>>
A B C D E F G H I J
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . . . . . . . . .
4 . . . . . . . . . .
5 . . . . . . . . . .
6 . . . . . . . . . .
7 . . . . . . . . . .
8 . . . . . . . . . .
9 . . . . . . . . . .
10 . . . . . . . . . .
Enter position, "show", "init" or "quit": show
<<Pacific Ocean>>
A B C D E F G H I J
1 . . . . . . . . . .
2 * . . . . . . . . .
3 * . . . . * . . . .
4 * . . . . * . . . .
5 * . . . . * . . . .
6 . * . . . . * * * *
7 . * . . . . . . . .
8 . * . . * * . . . .
9 . . . * . . . . . .
10 . . . * . . . . . .
Enter position, "show", "init" or "quit": quit
Bye...
The default board size is 10 x 10 and the computer arranges 6
ships of sizes between 2 and 4. The user can type in the position
to aim and hit by a space-delimited pair of a row position
(number) and a column position (alphabet) of the grid. The
result is hit or miss and is shown with '@' or '-' respectively at
the chosen position of the board. The dot '.' indicates
a position for choice. A command "show" discloses the
computer's arrangement of ships using '*' (as well as '@' at a
damaged position). The command "init" is to reset the game by
rearranging ships. The game is over when all the ships are
destroyed. The ship arrangement is random. Generation either
horizontal or vertical layout is also chosen at random.
The novel coronavirus pandemic is currently affecting every
single part of this world, and we are all hoping that the medical
researchers can come up with a vaccine as soon as possible so
that we can resume our normal day to day activities. Personally,
this pandemic has affected me in a lot of ways from my daily
routine to college and work at the same time. Having to take
classes online has been a challenge to me and I haven’t able to
grasp things quite well. My nature as a person was always
indoors and the crisis hasn’t affected my indoor activities, but I
miss having a cup of coffee while walking in the streets
especially on a warm day. Indoor games like chess and ludo
with friends online has been a healthy dose of workout.
Growing up just knowing how to cook the basic meals, using
YouTube videos, I have now advanced my cooking skills, and
once I move out of my parent's house after school, for sure, I
will be able to cook tasty meals for myself.
Talking about social effects, In a way, I think the current
condition has brought an idea of fairness into the limelight.
This crisis didn’t choose class, race or gender, or any other
discrimination in society. It, however, affected elderly people
the most, but that is due to their level of physical well-being. If
we see the flip side of the coin, the discrimination between race
and ethnicity was on the rise during the beginning of the crisis.
We read articles about Chinese students being beaten by white
Americans. I just hope we don’t see that happening after the
crisis is over.
Food security is a huge necessity during this time when more
than 24 million people are out of a job here in the US just
within five weeks, ("Impacts of the COVID-19 crisis on
employment: (potential) solutions for informal/ self-employed
workers," n.d.). The fact that one can afford to get meals every
single day is something to appreciate and should not be taken
for granted. Some parts of the world people are dying of hunger
during this period owing to the lockdowns, and people cannot
work, and they cannot afford to buy food.
To me, social media has proven to be a very useful tool during
this period. I have been using Facebook, Instagram, and other
platforms to connect with friends and families, find ideas for
my projects, and keep up with news at all times. This period has
also shown the need to evaluate the information given because
some information can cause unnecessary fear and some
information can be so useful if taken seriously and acted upon
early enough e.g., when the first patient in Wuhan was detected,
if WHO had alerted people much earlier the world would not be
at this position but China chose to assume things ("Caribbean
COVID-19 food security & livelihoods impact survey | World
food program," n.d.).
With the current condition of lockdown around the US and other
countries, learning has shifted to online to ensure that students
are safe. The idea is brilliant, but its a challenge for classes that
require students to have one on one interaction with the
equipment. It might benefit students who take part in theory
studies on the larger part. Online learning does not also
incorporate social equity. Research by PEW research center
shows by the end of 2019, 29% of Americans could not afford
smartphones (Pew Research Center, 2019). What happens to the
future of children from these families? They need to read to
uplift their families.
Education should not just be in theory like online learning is
portraying. Students need to come into contact with real-world
studies to understand what the job market needs. Therefore we
should all stay at home and hope for the crisis to end as soon as
possible for the economy to resuscitate and physical learning to
continue.
prog5.cpp
1 /* One-man Battleship Game Akira's Version implementation
template.
2 Use -std=c++11 to utilize regex input check. (C) Akira
Kawaguchi */
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 #include <cassert>
7 #include <sstream>
8 #include <algorithm>
9 #include <regex>
10 using namespace std;
11
12 const int DefaultBoardSize = 10; // default board size
is 10 x 10.
13 const int DefaultMinShipSize = 2; // default ship size
is [2, 4].
14 const int DefaultMaxShipSize = 4; //
15 const int DefaultShipCount = 6; // defulat ship count
in a map is 6.
16
17 enum class Command { INIT, SHOW, QUIT, BOMB };
18
19 class Cell {
20 enum mark { HIT, MISS, NONE };
21 mark m_status; // indicating bombed, missed, or not
selected.
22 bool m_ship; // indicating presence of ship.
23 public:
24 Cell() : m_status(NONE), m_ship(false) {}
25
26 friend ostream& operator<<(ostream& o, const Cell& c) {
27 switch (c.m_status) {
28 case HIT: o << '@'; break;
29 case MISS: o << '-'; break;
30 case NONE: o << '.'; break;
31 default: assert(false);
32 }
33 return o << ' ';
34 }
35 };
36
37 class Board {
38 string m_name; // map name.
39 int m_size; // n x n seamap size.
40 vector<vector<Cell> > m_map; // 2D sea map.
41 public:
42 Board(const string& n ="my map", const int s
=DefaultBoardSize) :
43 m_name(n), m_size(s) {
44 vector<Cell> a_row(m_size);
45 for (int i = 0; i < m_size; ++i) m_map.push_back(a_row);
46 init();
47 }
48 void init(const int n =DefaultShipCount) { // randomly set
ships in the map.
49 // not implemented.
50 }
51 bool bomb(const int row, const int col) { // bomb the ship!
52 // not implemented.
53 return true;
54 }
55 bool isover() const {
56 // not implemented.
57 return false;
58 }
59 friend ostream& operator<<(ostream& o, const Board& m)
{
60 o << " <<" << m.m_name << ">>" << endl << " ";
61 for (int row = 0; row < m.m_size; ++row) o << (char)('A'
+ row) << ' ';
62 o << endl;
Page 1
prog5.cpp
63 for (int row = 0; row < m.m_size; ++row) {
64 for (int col = 0; col < m.m_size; ++col) {
65 if (!col) o << setw(2) << right << 1 + row << ' ';
66 o << m.m_map[row][col];
67 }
68 o << endl;
69 }
70 return o;
71 }
72 };
73
74 /* Input parsing logic for this application. This one uses so-
called "regular
75 expressions" to prune out inconsistent input (i.e., syntactic
check) at
76 first and then apply more application-related inspections
(semantic check).
77 Note that there are three return values - a return value and
two non-const
78 references in the parameter list. */
79 Command parse(const int size, int& row, int& col) {
80 cout << "nEnter position, "show", "init" or "quit": ";
81 string line;
82 regex pattern1("show|init|quit"); // one word input.
83 regex pattern2("[0-9]+[[:blank:]]+[a-z]"); // two words with
space(s) between.
84
85 while (getline(cin, line)) { // read a whole line and convert
to lower cases.
86 transform(line.begin(), line.end(), line.begin(), ::tolower);
87 if (regex_match(line, pattern1)) { // match one word
input?
88 if (line.find("init") != string::npos) return
Command::INIT;
89 if (line.find("show") != string::npos) return
Command::SHOW;
90 if (line.find("quit") != string::npos) return
Command::QUIT;
91 } // you can use enum if you want above instead of a
number return.
92 if (regex_match(line, pattern2)) { // match two word
input?
93 string c, r;
94 istringstream iss(line); // then read int two
words.
95 iss >> c >> r; // stringstream is the one
to use!
96 assert(!iss.fail()); // this will not happen
(why?)
97 row = atoi(c.c_str()) - 1; // apply semantic check
for col,
98 col = r[0] - 'a'; // and row values.
99 if (row >= 0 && row < size && col >= 0 && col < size)
100 return Command::BOMB;
101 }
102 cout << "Input error, try again: ";
103 }
104 assert(false); // to make sure not to
reach here.
105 }
106
107 int main() {
108 const int size = DefaultBoardSize; // instantiate a
board object with
109 Board b("Pacific Ocean", size); // game (war)
name and board size.
110
111 while (true) {
112 cout << b;
113
114 int row, col;
115 switch (parse(size, row, col)) {
116 case Command::QUIT: goto END; // "quit" is to
end the game.
117 case Command::SHOW: break; // "show" is to
show the answer.
118 case Command::INIT: b.init(); continue; // "init" is to
restart the game.
119 case Command::BOMB: break; // other correct
input.
120 default: abort(); // should not reach.
121 }
122 bool r = b.bomb(row, col); // otherwise do the
game...
123 cout << "You " << (r? "ahit :)" : "missed :(") << endl;
124 if (b.isover()) {
Page 2
prog5.cpp
125 cout << "You bombed all ships, congratulations!" <<
endl;
126 break;
127 }
128 }
129 END:
130 cout << "Bye..." << endl;
131 return 0;
132 }
133
Page 3
Your task in this assignment is to implement a simplified guessing

More Related Content

Similar to Your task in this assignment is to implement a simplified guessing

Assignments that Meet the Needs of Exceptional Students without Disadvantagin...
Assignments that Meet the Needs of Exceptional Students without Disadvantagin...Assignments that Meet the Needs of Exceptional Students without Disadvantagin...
Assignments that Meet the Needs of Exceptional Students without Disadvantagin...Katrin Becker
 
Chipmunk physics presentation
Chipmunk physics presentationChipmunk physics presentation
Chipmunk physics presentationCarl Brown
 
10 am b_2018
10 am b_201810 am b_2018
10 am b_20184book
 
MSc Software Development Go Program Dissertation
MSc Software Development Go Program DissertationMSc Software Development Go Program Dissertation
MSc Software Development Go Program DissertationTom Reed
 
K 3214 paper-iii
K 3214 paper-iiiK 3214 paper-iii
K 3214 paper-iiiPramoda Raj
 
Vp1 ai o-v&g-extn7
Vp1 ai o-v&g-extn7Vp1 ai o-v&g-extn7
Vp1 ai o-v&g-extn7almasymejo
 
Metodo de ukulele
Metodo de ukuleleMetodo de ukulele
Metodo de ukuleleSaulo Gomes
 
digital-sat-practice-test-4.pdf digital-sat-practice-test-4
digital-sat-practice-test-4.pdf digital-sat-practice-test-4digital-sat-practice-test-4.pdf digital-sat-practice-test-4
digital-sat-practice-test-4.pdf digital-sat-practice-test-4RickJonshon
 
1 John Augustus Stone, Excerpts from Metamora; Or, the L.docx
1 John Augustus Stone, Excerpts from Metamora; Or, the L.docx1 John Augustus Stone, Excerpts from Metamora; Or, the L.docx
1 John Augustus Stone, Excerpts from Metamora; Or, the L.docxhoney725342
 

Similar to Your task in this assignment is to implement a simplified guessing (18)

Synopsis tic tac toe
Synopsis tic tac toeSynopsis tic tac toe
Synopsis tic tac toe
 
En101 16-4
En101 16-4En101 16-4
En101 16-4
 
Basics cocos2d
Basics cocos2dBasics cocos2d
Basics cocos2d
 
9 am b_2017
9 am b_20179 am b_2017
9 am b_2017
 
Writers at work
Writers at workWriters at work
Writers at work
 
Assignments that Meet the Needs of Exceptional Students without Disadvantagin...
Assignments that Meet the Needs of Exceptional Students without Disadvantagin...Assignments that Meet the Needs of Exceptional Students without Disadvantagin...
Assignments that Meet the Needs of Exceptional Students without Disadvantagin...
 
Chipmunk physics presentation
Chipmunk physics presentationChipmunk physics presentation
Chipmunk physics presentation
 
1
11
1
 
10 am b_2018
10 am b_201810 am b_2018
10 am b_2018
 
Lesson-8-Asteroid.pptx
Lesson-8-Asteroid.pptxLesson-8-Asteroid.pptx
Lesson-8-Asteroid.pptx
 
MSc Software Development Go Program Dissertation
MSc Software Development Go Program DissertationMSc Software Development Go Program Dissertation
MSc Software Development Go Program Dissertation
 
K 3214 paper-iii
K 3214 paper-iiiK 3214 paper-iii
K 3214 paper-iii
 
Vp1 ai o-v&g-extn7
Vp1 ai o-v&g-extn7Vp1 ai o-v&g-extn7
Vp1 ai o-v&g-extn7
 
De 132
De 132De 132
De 132
 
Metodo de ukulele
Metodo de ukuleleMetodo de ukulele
Metodo de ukulele
 
Test for 10th grade.
Test for 10th grade.Test for 10th grade.
Test for 10th grade.
 
digital-sat-practice-test-4.pdf digital-sat-practice-test-4
digital-sat-practice-test-4.pdf digital-sat-practice-test-4digital-sat-practice-test-4.pdf digital-sat-practice-test-4
digital-sat-practice-test-4.pdf digital-sat-practice-test-4
 
1 John Augustus Stone, Excerpts from Metamora; Or, the L.docx
1 John Augustus Stone, Excerpts from Metamora; Or, the L.docx1 John Augustus Stone, Excerpts from Metamora; Or, the L.docx
1 John Augustus Stone, Excerpts from Metamora; Or, the L.docx
 

More from rochellscroop

In this assignment, you will analyze Fiedlers Contingency Theor.docx
In this assignment, you will analyze Fiedlers Contingency Theor.docxIn this assignment, you will analyze Fiedlers Contingency Theor.docx
In this assignment, you will analyze Fiedlers Contingency Theor.docxrochellscroop
 
In this assignment, you will be a Supreme Court Justice deciding on .docx
In this assignment, you will be a Supreme Court Justice deciding on .docxIn this assignment, you will be a Supreme Court Justice deciding on .docx
In this assignment, you will be a Supreme Court Justice deciding on .docxrochellscroop
 
In this assignment, you will apply your knowledge of cultural influe.docx
In this assignment, you will apply your knowledge of cultural influe.docxIn this assignment, you will apply your knowledge of cultural influe.docx
In this assignment, you will apply your knowledge of cultural influe.docxrochellscroop
 
In this assignment you will analyze the organizational behavior of y.docx
In this assignment you will analyze the organizational behavior of y.docxIn this assignment you will analyze the organizational behavior of y.docx
In this assignment you will analyze the organizational behavior of y.docxrochellscroop
 
In this assessment, students will read the case study provided.  Stu.docx
In this assessment, students will read the case study provided.  Stu.docxIn this assessment, students will read the case study provided.  Stu.docx
In this assessment, students will read the case study provided.  Stu.docxrochellscroop
 
In this assessment, students will read the case study provided.docx
In this assessment, students will read the case study provided.docxIn this assessment, students will read the case study provided.docx
In this assessment, students will read the case study provided.docxrochellscroop
 
In the Wealth of Nations (1776) Smith describes the economy as a sel.docx
In the Wealth of Nations (1776) Smith describes the economy as a sel.docxIn the Wealth of Nations (1776) Smith describes the economy as a sel.docx
In the Wealth of Nations (1776) Smith describes the economy as a sel.docxrochellscroop
 
In the Unit 4 assignment you learned about a complex international o.docx
In the Unit 4 assignment you learned about a complex international o.docxIn the Unit 4 assignment you learned about a complex international o.docx
In the Unit 4 assignment you learned about a complex international o.docxrochellscroop
 
In the Week 4 Case Study AssessmentResources, Mrs. Ashland w.docx
In the Week 4 Case Study AssessmentResources, Mrs. Ashland w.docxIn the Week 4 Case Study AssessmentResources, Mrs. Ashland w.docx
In the Week 4 Case Study AssessmentResources, Mrs. Ashland w.docxrochellscroop
 
In the story The Lady or the Tiger , which comes through the door, t.docx
In the story The Lady or the Tiger , which comes through the door, t.docxIn the story The Lady or the Tiger , which comes through the door, t.docx
In the story The Lady or the Tiger , which comes through the door, t.docxrochellscroop
 
In the third week of the session, you will submit a review of a scho.docx
In the third week of the session, you will submit a review of a scho.docxIn the third week of the session, you will submit a review of a scho.docx
In the third week of the session, you will submit a review of a scho.docxrochellscroop
 
In The Road Not Taken,” Robert Frost writes figuratively about the .docx
In The Road Not Taken,” Robert Frost writes figuratively about the .docxIn The Road Not Taken,” Robert Frost writes figuratively about the .docx
In The Road Not Taken,” Robert Frost writes figuratively about the .docxrochellscroop
 
In the scenarios and resulting simulations, Robert Donovan, a Jurisv.docx
In the scenarios and resulting simulations, Robert Donovan, a Jurisv.docxIn the scenarios and resulting simulations, Robert Donovan, a Jurisv.docx
In the scenarios and resulting simulations, Robert Donovan, a Jurisv.docxrochellscroop
 
In the past weeks, students have learned about leaders and leaders.docx
In the past weeks, students have learned about leaders and leaders.docxIn the past weeks, students have learned about leaders and leaders.docx
In the past weeks, students have learned about leaders and leaders.docxrochellscroop
 
In the poem, The Terrorist, He Watches” by Wislawa Szmborska, how w.docx
In the poem, The Terrorist, He Watches” by Wislawa Szmborska, how w.docxIn the poem, The Terrorist, He Watches” by Wislawa Szmborska, how w.docx
In the poem, The Terrorist, He Watches” by Wislawa Szmborska, how w.docxrochellscroop
 
In the midsized town of Centervale, there is no more crime than one .docx
In the midsized town of Centervale, there is no more crime than one .docxIn the midsized town of Centervale, there is no more crime than one .docx
In the midsized town of Centervale, there is no more crime than one .docxrochellscroop
 
In the movie, the school board decides to make Coach Boone the head .docx
In the movie, the school board decides to make Coach Boone the head .docxIn the movie, the school board decides to make Coach Boone the head .docx
In the movie, the school board decides to make Coach Boone the head .docxrochellscroop
 
In the mid-seventeenth century, Dutch scientist Jan Baptista van Hel.docx
In the mid-seventeenth century, Dutch scientist Jan Baptista van Hel.docxIn the mid-seventeenth century, Dutch scientist Jan Baptista van Hel.docx
In the mid-seventeenth century, Dutch scientist Jan Baptista van Hel.docxrochellscroop
 
In the early 20th century, the specter of infectious disease lurke.docx
In the early 20th century, the specter of infectious disease lurke.docxIn the early 20th century, the specter of infectious disease lurke.docx
In the early 20th century, the specter of infectious disease lurke.docxrochellscroop
 
In the Group Wiki, write by Day 5 a summary to address the follo.docx
In the Group Wiki, write by Day 5 a summary to address the follo.docxIn the Group Wiki, write by Day 5 a summary to address the follo.docx
In the Group Wiki, write by Day 5 a summary to address the follo.docxrochellscroop
 

More from rochellscroop (20)

In this assignment, you will analyze Fiedlers Contingency Theor.docx
In this assignment, you will analyze Fiedlers Contingency Theor.docxIn this assignment, you will analyze Fiedlers Contingency Theor.docx
In this assignment, you will analyze Fiedlers Contingency Theor.docx
 
In this assignment, you will be a Supreme Court Justice deciding on .docx
In this assignment, you will be a Supreme Court Justice deciding on .docxIn this assignment, you will be a Supreme Court Justice deciding on .docx
In this assignment, you will be a Supreme Court Justice deciding on .docx
 
In this assignment, you will apply your knowledge of cultural influe.docx
In this assignment, you will apply your knowledge of cultural influe.docxIn this assignment, you will apply your knowledge of cultural influe.docx
In this assignment, you will apply your knowledge of cultural influe.docx
 
In this assignment you will analyze the organizational behavior of y.docx
In this assignment you will analyze the organizational behavior of y.docxIn this assignment you will analyze the organizational behavior of y.docx
In this assignment you will analyze the organizational behavior of y.docx
 
In this assessment, students will read the case study provided.  Stu.docx
In this assessment, students will read the case study provided.  Stu.docxIn this assessment, students will read the case study provided.  Stu.docx
In this assessment, students will read the case study provided.  Stu.docx
 
In this assessment, students will read the case study provided.docx
In this assessment, students will read the case study provided.docxIn this assessment, students will read the case study provided.docx
In this assessment, students will read the case study provided.docx
 
In the Wealth of Nations (1776) Smith describes the economy as a sel.docx
In the Wealth of Nations (1776) Smith describes the economy as a sel.docxIn the Wealth of Nations (1776) Smith describes the economy as a sel.docx
In the Wealth of Nations (1776) Smith describes the economy as a sel.docx
 
In the Unit 4 assignment you learned about a complex international o.docx
In the Unit 4 assignment you learned about a complex international o.docxIn the Unit 4 assignment you learned about a complex international o.docx
In the Unit 4 assignment you learned about a complex international o.docx
 
In the Week 4 Case Study AssessmentResources, Mrs. Ashland w.docx
In the Week 4 Case Study AssessmentResources, Mrs. Ashland w.docxIn the Week 4 Case Study AssessmentResources, Mrs. Ashland w.docx
In the Week 4 Case Study AssessmentResources, Mrs. Ashland w.docx
 
In the story The Lady or the Tiger , which comes through the door, t.docx
In the story The Lady or the Tiger , which comes through the door, t.docxIn the story The Lady or the Tiger , which comes through the door, t.docx
In the story The Lady or the Tiger , which comes through the door, t.docx
 
In the third week of the session, you will submit a review of a scho.docx
In the third week of the session, you will submit a review of a scho.docxIn the third week of the session, you will submit a review of a scho.docx
In the third week of the session, you will submit a review of a scho.docx
 
In The Road Not Taken,” Robert Frost writes figuratively about the .docx
In The Road Not Taken,” Robert Frost writes figuratively about the .docxIn The Road Not Taken,” Robert Frost writes figuratively about the .docx
In The Road Not Taken,” Robert Frost writes figuratively about the .docx
 
In the scenarios and resulting simulations, Robert Donovan, a Jurisv.docx
In the scenarios and resulting simulations, Robert Donovan, a Jurisv.docxIn the scenarios and resulting simulations, Robert Donovan, a Jurisv.docx
In the scenarios and resulting simulations, Robert Donovan, a Jurisv.docx
 
In the past weeks, students have learned about leaders and leaders.docx
In the past weeks, students have learned about leaders and leaders.docxIn the past weeks, students have learned about leaders and leaders.docx
In the past weeks, students have learned about leaders and leaders.docx
 
In the poem, The Terrorist, He Watches” by Wislawa Szmborska, how w.docx
In the poem, The Terrorist, He Watches” by Wislawa Szmborska, how w.docxIn the poem, The Terrorist, He Watches” by Wislawa Szmborska, how w.docx
In the poem, The Terrorist, He Watches” by Wislawa Szmborska, how w.docx
 
In the midsized town of Centervale, there is no more crime than one .docx
In the midsized town of Centervale, there is no more crime than one .docxIn the midsized town of Centervale, there is no more crime than one .docx
In the midsized town of Centervale, there is no more crime than one .docx
 
In the movie, the school board decides to make Coach Boone the head .docx
In the movie, the school board decides to make Coach Boone the head .docxIn the movie, the school board decides to make Coach Boone the head .docx
In the movie, the school board decides to make Coach Boone the head .docx
 
In the mid-seventeenth century, Dutch scientist Jan Baptista van Hel.docx
In the mid-seventeenth century, Dutch scientist Jan Baptista van Hel.docxIn the mid-seventeenth century, Dutch scientist Jan Baptista van Hel.docx
In the mid-seventeenth century, Dutch scientist Jan Baptista van Hel.docx
 
In the early 20th century, the specter of infectious disease lurke.docx
In the early 20th century, the specter of infectious disease lurke.docxIn the early 20th century, the specter of infectious disease lurke.docx
In the early 20th century, the specter of infectious disease lurke.docx
 
In the Group Wiki, write by Day 5 a summary to address the follo.docx
In the Group Wiki, write by Day 5 a summary to address the follo.docxIn the Group Wiki, write by Day 5 a summary to address the follo.docx
In the Group Wiki, write by Day 5 a summary to address the follo.docx
 

Recently uploaded

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

Your task in this assignment is to implement a simplified guessing

  • 1. Your task in this assignment is to implement a simplified guessing game, hinted by a well-known plastic board game called Battleship. The computer arranges ships on the grid structure in which each ship occupies a number of consecutive positions on the grid. Those ships are arranged either horizontally or vertically. The number of positions for each ship is determined by the type of the ship. The ship cannot overlap and only one ship can occupy any given position in the grid. You can play a real version on the web such as this to get an idea. The version to realize in this assignment is simpler and a one-man based game in which you are bombing those ships generated by your computer. The next sample session will illustrate the entire scheme: There are 6 ships. Must bomb 18 places to destroy all... <<Pacific Ocean>> A B C D E F G H I J 1 . . . . . . . . . . 2 . . . . . . . . . . 3 . . . . . . . . . . 4 . . . . . . . . . . 5 . . . . . . . . . . 6 . . . . . . . . . . 7 . . . . . . . . . . 8 . . . . . . . . . . 9 . . . . . . . . . . 10 . . . . . . . . . . Enter position, "show", "init" or "quit": 4 G You missed :( <<Pacific Ocean>> A B C D E F G H I J 1 . . . . . . . . . . 2 . . . . . . . . . . 3 . . . . . . . . . .
  • 2. 4 . . . . . . - . . . 5 . . . . . . . . . . 6 . . . . . . . . . . 7 . . . . . . . . . . 8 . . . . . . . . . . 9 . . . . . . . . . . 10 . . . . . . . . . . Enter position, "show", "init" or "quit": 8 b You hit :) <<Pacific Ocean>> A B C D E F G H I J 1 . . . . . . . . . . 2 . . . . . . . . . . 3 . . . . . . . . . . 4 . . . . . . - . . . 5 . . . . . . . . . . 6 . . . . . . . . . . 7 . . . . . . . . . . 8 . @ . . . . . . . . 9 . . . . . . . . . . 10 . . . . . . . . . . Enter position, "show", "init" or "quit": show <<Pacific Ocean>> A B C D E F G H I J 1 . * . . * * * . . . 2 . * . . . . . . . . 3 . * . . * . . . . . 4 . . . . * . - . . . 5 . . . . * . . . * * 6 . . . * * . . . . . 7 . * . * . . . . . . 8 . @ . * . . . . . . 9 . * . . . . . . . . 10 . * . . . . . . . .
  • 3. Enter position, "show", "init" or "quit": 8 B You bomed same place... You missed :( <<Pacific Ocean>> A B C D E F G H I J 1 . . . . . . . . . . 2 . . . . . . . . . . 3 . . . . . . . . . . 4 . . . . . . - . . . 5 . . . . . . . . . . 6 . . . . . . . . . . 7 . . . . . . . . . . 8 . @ . . . . . . . . 9 . . . . . . . . . . 10 . . . . . . . . . . Enter position, "show", "init" or "quit": init There are 6 ships. Must bomb 18 places to destroy all... <<Pacific Ocean>> A B C D E F G H I J 1 . . . . . . . . . . 2 . . . . . . . . . . 3 . . . . . . . . . . 4 . . . . . . . . . . 5 . . . . . . . . . . 6 . . . . . . . . . . 7 . . . . . . . . . . 8 . . . . . . . . . . 9 . . . . . . . . . . 10 . . . . . . . . . . Enter position, "show", "init" or "quit": show <<Pacific Ocean>> A B C D E F G H I J 1 . . . . . . . . . . 2 * . . . . . . . . .
  • 4. 3 * . . . . * . . . . 4 * . . . . * . . . . 5 * . . . . * . . . . 6 . * . . . . * * * * 7 . * . . . . . . . . 8 . * . . * * . . . . 9 . . . * . . . . . . 10 . . . * . . . . . . Enter position, "show", "init" or "quit": quit Bye... The default board size is 10 x 10 and the computer arranges 6 ships of sizes between 2 and 4. The user can type in the position to aim and hit by a space-delimited pair of a row position (number) and a column position (alphabet) of the grid. The result is hit or miss and is shown with '@' or '-' respectively at the chosen position of the board. The dot '.' indicates a position for choice. A command "show" discloses the computer's arrangement of ships using '*' (as well as '@' at a damaged position). The command "init" is to reset the game by rearranging ships. The game is over when all the ships are destroyed. The ship arrangement is random. Generation either horizontal or vertical layout is also chosen at random. The novel coronavirus pandemic is currently affecting every single part of this world, and we are all hoping that the medical researchers can come up with a vaccine as soon as possible so that we can resume our normal day to day activities. Personally, this pandemic has affected me in a lot of ways from my daily routine to college and work at the same time. Having to take classes online has been a challenge to me and I haven’t able to grasp things quite well. My nature as a person was always
  • 5. indoors and the crisis hasn’t affected my indoor activities, but I miss having a cup of coffee while walking in the streets especially on a warm day. Indoor games like chess and ludo with friends online has been a healthy dose of workout. Growing up just knowing how to cook the basic meals, using YouTube videos, I have now advanced my cooking skills, and once I move out of my parent's house after school, for sure, I will be able to cook tasty meals for myself. Talking about social effects, In a way, I think the current condition has brought an idea of fairness into the limelight. This crisis didn’t choose class, race or gender, or any other discrimination in society. It, however, affected elderly people the most, but that is due to their level of physical well-being. If we see the flip side of the coin, the discrimination between race and ethnicity was on the rise during the beginning of the crisis. We read articles about Chinese students being beaten by white Americans. I just hope we don’t see that happening after the crisis is over. Food security is a huge necessity during this time when more than 24 million people are out of a job here in the US just within five weeks, ("Impacts of the COVID-19 crisis on employment: (potential) solutions for informal/ self-employed workers," n.d.). The fact that one can afford to get meals every single day is something to appreciate and should not be taken for granted. Some parts of the world people are dying of hunger during this period owing to the lockdowns, and people cannot work, and they cannot afford to buy food. To me, social media has proven to be a very useful tool during this period. I have been using Facebook, Instagram, and other platforms to connect with friends and families, find ideas for my projects, and keep up with news at all times. This period has also shown the need to evaluate the information given because some information can cause unnecessary fear and some information can be so useful if taken seriously and acted upon early enough e.g., when the first patient in Wuhan was detected, if WHO had alerted people much earlier the world would not be
  • 6. at this position but China chose to assume things ("Caribbean COVID-19 food security & livelihoods impact survey | World food program," n.d.). With the current condition of lockdown around the US and other countries, learning has shifted to online to ensure that students are safe. The idea is brilliant, but its a challenge for classes that require students to have one on one interaction with the equipment. It might benefit students who take part in theory studies on the larger part. Online learning does not also incorporate social equity. Research by PEW research center shows by the end of 2019, 29% of Americans could not afford smartphones (Pew Research Center, 2019). What happens to the future of children from these families? They need to read to uplift their families. Education should not just be in theory like online learning is portraying. Students need to come into contact with real-world studies to understand what the job market needs. Therefore we should all stay at home and hope for the crisis to end as soon as possible for the economy to resuscitate and physical learning to continue. prog5.cpp 1 /* One-man Battleship Game Akira's Version implementation template. 2 Use -std=c++11 to utilize regex input check. (C) Akira Kawaguchi */ 3 #include <iostream> 4 #include <iomanip> 5 #include <vector> 6 #include <cassert>
  • 7. 7 #include <sstream> 8 #include <algorithm> 9 #include <regex> 10 using namespace std; 11 12 const int DefaultBoardSize = 10; // default board size is 10 x 10. 13 const int DefaultMinShipSize = 2; // default ship size is [2, 4]. 14 const int DefaultMaxShipSize = 4; // 15 const int DefaultShipCount = 6; // defulat ship count in a map is 6. 16 17 enum class Command { INIT, SHOW, QUIT, BOMB }; 18 19 class Cell { 20 enum mark { HIT, MISS, NONE }; 21 mark m_status; // indicating bombed, missed, or not selected. 22 bool m_ship; // indicating presence of ship. 23 public: 24 Cell() : m_status(NONE), m_ship(false) {} 25 26 friend ostream& operator<<(ostream& o, const Cell& c) { 27 switch (c.m_status) { 28 case HIT: o << '@'; break; 29 case MISS: o << '-'; break; 30 case NONE: o << '.'; break; 31 default: assert(false); 32 } 33 return o << ' '; 34 } 35 }; 36 37 class Board { 38 string m_name; // map name.
  • 8. 39 int m_size; // n x n seamap size. 40 vector<vector<Cell> > m_map; // 2D sea map. 41 public: 42 Board(const string& n ="my map", const int s =DefaultBoardSize) : 43 m_name(n), m_size(s) { 44 vector<Cell> a_row(m_size); 45 for (int i = 0; i < m_size; ++i) m_map.push_back(a_row); 46 init(); 47 } 48 void init(const int n =DefaultShipCount) { // randomly set ships in the map. 49 // not implemented. 50 } 51 bool bomb(const int row, const int col) { // bomb the ship! 52 // not implemented. 53 return true; 54 } 55 bool isover() const { 56 // not implemented. 57 return false; 58 } 59 friend ostream& operator<<(ostream& o, const Board& m) { 60 o << " <<" << m.m_name << ">>" << endl << " "; 61 for (int row = 0; row < m.m_size; ++row) o << (char)('A' + row) << ' '; 62 o << endl; Page 1 prog5.cpp 63 for (int row = 0; row < m.m_size; ++row) {
  • 9. 64 for (int col = 0; col < m.m_size; ++col) { 65 if (!col) o << setw(2) << right << 1 + row << ' '; 66 o << m.m_map[row][col]; 67 } 68 o << endl; 69 } 70 return o; 71 } 72 }; 73 74 /* Input parsing logic for this application. This one uses so- called "regular 75 expressions" to prune out inconsistent input (i.e., syntactic check) at 76 first and then apply more application-related inspections (semantic check). 77 Note that there are three return values - a return value and two non-const 78 references in the parameter list. */ 79 Command parse(const int size, int& row, int& col) { 80 cout << "nEnter position, "show", "init" or "quit": "; 81 string line; 82 regex pattern1("show|init|quit"); // one word input. 83 regex pattern2("[0-9]+[[:blank:]]+[a-z]"); // two words with space(s) between. 84 85 while (getline(cin, line)) { // read a whole line and convert to lower cases. 86 transform(line.begin(), line.end(), line.begin(), ::tolower); 87 if (regex_match(line, pattern1)) { // match one word input? 88 if (line.find("init") != string::npos) return Command::INIT; 89 if (line.find("show") != string::npos) return Command::SHOW; 90 if (line.find("quit") != string::npos) return
  • 10. Command::QUIT; 91 } // you can use enum if you want above instead of a number return. 92 if (regex_match(line, pattern2)) { // match two word input? 93 string c, r; 94 istringstream iss(line); // then read int two words. 95 iss >> c >> r; // stringstream is the one to use! 96 assert(!iss.fail()); // this will not happen (why?) 97 row = atoi(c.c_str()) - 1; // apply semantic check for col, 98 col = r[0] - 'a'; // and row values. 99 if (row >= 0 && row < size && col >= 0 && col < size) 100 return Command::BOMB; 101 } 102 cout << "Input error, try again: "; 103 } 104 assert(false); // to make sure not to reach here. 105 } 106 107 int main() { 108 const int size = DefaultBoardSize; // instantiate a board object with 109 Board b("Pacific Ocean", size); // game (war) name and board size. 110 111 while (true) { 112 cout << b; 113 114 int row, col; 115 switch (parse(size, row, col)) { 116 case Command::QUIT: goto END; // "quit" is to
  • 11. end the game. 117 case Command::SHOW: break; // "show" is to show the answer. 118 case Command::INIT: b.init(); continue; // "init" is to restart the game. 119 case Command::BOMB: break; // other correct input. 120 default: abort(); // should not reach. 121 } 122 bool r = b.bomb(row, col); // otherwise do the game... 123 cout << "You " << (r? "ahit :)" : "missed :(") << endl; 124 if (b.isover()) { Page 2 prog5.cpp 125 cout << "You bombed all ships, congratulations!" << endl; 126 break; 127 } 128 } 129 END: 130 cout << "Bye..." << endl; 131 return 0; 132 } 133 Page 3