Instead of checking for stream failure (in
Dungeon::select_room_to_move
) usingfail, use
std::cin's
operator bool:
if (!std::cin) /fail/;`.if (game_over == true)
can be simplified toif (game_over)
.The introduction text is not up-to-date. There are three pits and super bats, not two. Might want to use the actual variables instead of hardcoding text.
It's my understanding that neighbors cannot ever be
nullptr
, so the extra if statement for it is unnecessary (wumpus.cpp:226). Might want to consider using anassert
instead.It seems like you are using
player_room
a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.Dungeon::shoot_arrow
has a bug. If I want to shoot an arrow into3-5-9
, then I only lose one arrow. I don't think that this intended. Also, if I shoot my last arrow into a non-existent room, then I can illegally continue ;).Dungeon::move_player
has a bug, it moves the player into the wrong room. That's becauserooms
is not sorted, sorooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)
Instead of checking for stream failure (in
Dungeon::select_room_to_move
) usingfail, use
std::cin's
operator bool:
if (!std::cin) /fail/;`.if (game_over == true)
can be simplified toif (game_over)
.The introduction text is not up-to-date. There are three pits and super bats, not two. Might want to use the actual variables instead of hardcoding text.
It's my understanding that neighbors cannot ever be
nullptr
, so the extra if statement for it is unnecessary (wumpus.cpp:226). Might want to consider using anassert
instead.It seems like you are using
player_room
a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.Dungeon::shoot_arrow
has a bug. If I want to shoot an arrow into3-5-9
, then I only lose one arrow. I don't think that this intended. Also, if I shoot my last arrow into a non-existent room, then I can illegally continue ;).Dungeon::move_player
has a bug, it moves the player into the wrong room. That's becauserooms
is not sorted, sorooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)
Instead of checking for stream failure (in
Dungeon::select_room_to_move
) usingfail, use
std::cin's
operator bool:
if (!std::cin) /fail/;`.if (game_over == true)
can be simplified toif (game_over)
.The introduction text is not up-to-date. There are three pits and super bats, not two. Might want to use the actual variables instead of hardcoding text.
It's my understanding that neighbors cannot ever be
nullptr
, so the extra if statement for it is unnecessary (wumpus.cpp:226). Might want to consider using anassert
instead.It seems like you are using
player_room
a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.Dungeon::shoot_arrow
has a bug. If I shoot my last arrow into a non-existent room, then I can illegally continue ;)Dungeon::move_player
has a bug, it moves the player into the wrong room. That's becauserooms
is not sorted, sorooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)
Instead of checking for stream failure (in
Dungeon::select_room_to_move
) usingfail, use
std::cin's
operator bool:
if (!std::cin) /fail/;`.(I'm not sure about this point). Isn't
distribution
inget_random
not supposed to bestatic
too?if (game_over == true)
can be simplified toif (game_over)
.The introduction text is not up-to-date. There are three pits and super bats, not two. Might want to use the actual variables instead of hardcoding text.
It's my understanding that neighbors cannot ever be
nullptr
, so the extra if statement for it is unnecessary (wumpus.cpp:226). Might want to consider using anassert
instead.It seems like you are using
player_room
a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.Dungeon::shoot_arrow
has a bug. If I want to shoot an arrow into3-5-9
, then I only lose one arrow. I don't think that this intended. Also, if I shoot my last arrow into a non-existent room, then I can illegally continue ;).Dungeon::move_player
has a bug, it moves the player into the wrong room. That's becauserooms
is not sorted, sorooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)
Instead of checking for stream failure (in
Dungeon::select_room_to_move
) usingfail, use
std::cin's
operator bool:
if (!std::cin) /fail/;`.(I'm not sure about this point). Isn't
distribution
inget_random
not supposed to bestatic
too?if (game_over == true)
can be simplified toif (game_over)
.The introduction text is not up-to-date. There are three pits and super bats, not two. Might want to use the actual variables instead of hardcoding text.
It's my understanding that neighbors cannot ever be
nullptr
, so the extra if statement for it is unnecessary (wumpus.cpp:226). Might want to consider using anassert
instead.It seems like you are using
player_room
a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.Dungeon::shoot_arrow
has a bug. If I want to shoot an arrow into3-5-9
, then I only lose one arrow. I don't think that this intended. Also, if I shoot my last arrow into a non-existent room, then I can illegally continue ;).Dungeon::move_player
has a bug, it moves the player into the wrong room. That's becauserooms
is not sorted, sorooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)
Instead of checking for stream failure (in
Dungeon::select_room_to_move
) usingfail, use
std::cin's
operator bool:
if (!std::cin) /fail/;`.if (game_over == true)
can be simplified toif (game_over)
.The introduction text is not up-to-date. There are three pits and super bats, not two. Might want to use the actual variables instead of hardcoding text.
It's my understanding that neighbors cannot ever be
nullptr
, so the extra if statement for it is unnecessary (wumpus.cpp:226). Might want to consider using anassert
instead.It seems like you are using
player_room
a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.Dungeon::shoot_arrow
has a bug. If I want to shoot an arrow into3-5-9
, then I only lose one arrow. I don't think that this intended. Also, if I shoot my last arrow into a non-existent room, then I can illegally continue ;).Dungeon::move_player
has a bug, it moves the player into the wrong room. That's becauserooms
is not sorted, sorooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)
Instead of checking for stream failure (in
Dungeon::select_room_to_move
) usingfail, use
std::cin's
operator bool:
if (!std::cin) /fail/;`.(I'm not sure about this point). Isn't
distribution
inget_random
not supposed to bestatic
too?if (game_over == true)
can be simplified toif (game_over)
.The introduction text is not up-to-date. There are three pits and super bats, not two. Might want to use the actual variables instead of hardcoding text.
It's my understanding that neighbors cannot ever be
nullptr
, so the extra if statement for it is unnecessary (wumpus.cpp:226). Might want to consider using anassert
instead.Instead of having aIt seems like you are using
has_wumpusplayer_room
, a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.has_pitDungeon::shoot_arrow
, has a bug. If I want to shoot an arrow intohas_whatever3-5-9
, then I only lose one arrow. I don't think that this intended. Also, if I shoot my last arrow into a non-existent room, then I can illegally continue ;).Dungeon::move_player
has a bug, it's better to use oneit moves the player into the wrong room. That's becauseenumrooms
andis not sorted, sohas_pitrooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)enum class RoomInhabitant { Nobody, Player, Wumpus, Bat };
Then you can also use a switch
instead of an if cascade if you'd like. This has also an additional advantage is that you cannot break invariants easily: In your posted code, you can have a room with has_pit == has_bat == true
, which is not supposed to be possible. With an enum you do not have this problem.
It seems like you are using
player_room
a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.Dungeon::shoot_arrow
has a bug. If I want to shoot an arrow into3-5-9
, then I only lose one arrow. I don't think that this intended. Also, if I shoot my last arrow into a non-existent room, then I can illegally continue ;).Dungeon::move_player
has a bug, it moves the player into the wrong room. That's becauserooms
is not sorted, sorooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)
Instead of checking for stream failure (in
Dungeon::select_room_to_move
) usingfail, use
std::cin's
operator bool:
if (!std::cin) /fail/;`.(I'm not sure about this point). Isn't
distribution
inget_random
not supposed to bestatic
too?if (game_over == true)
can be simplified toif (game_over)
.The introduction text is not up-to-date. There are three pits and super bats, not two. Might want to use the actual variables instead of hardcoding text.
It's my understanding that neighbors cannot ever be
nullptr
, so the extra if statement for it is unnecessary (wumpus.cpp:226). Might want to consider using anassert
instead.Instead of having a
has_wumpus
,has_pit
,has_whatever
, ..., it's better to use oneenum
andhas_pit
:enum class RoomInhabitant { Nobody, Player, Wumpus, Bat };
Then you can also use a switch
instead of an if cascade if you'd like. This has also an additional advantage is that you cannot break invariants easily: In your posted code, you can have a room with has_pit == has_bat == true
, which is not supposed to be possible. With an enum you do not have this problem.
It seems like you are using
player_room
a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.Dungeon::shoot_arrow
has a bug. If I want to shoot an arrow into3-5-9
, then I only lose one arrow. I don't think that this intended. Also, if I shoot my last arrow into a non-existent room, then I can illegally continue ;).Dungeon::move_player
has a bug, it moves the player into the wrong room. That's becauserooms
is not sorted, sorooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)
Instead of checking for stream failure (in
Dungeon::select_room_to_move
) usingfail, use
std::cin's
operator bool:
if (!std::cin) /fail/;`.(I'm not sure about this point). Isn't
distribution
inget_random
not supposed to bestatic
too?if (game_over == true)
can be simplified toif (game_over)
.The introduction text is not up-to-date. There are three pits and super bats, not two. Might want to use the actual variables instead of hardcoding text.
It's my understanding that neighbors cannot ever be
nullptr
, so the extra if statement for it is unnecessary (wumpus.cpp:226). Might want to consider using anassert
instead.It seems like you are using
player_room
a lot. You might want to consider using a member variable for that so that you avoid to iterate over (potentially) the whole room container.Dungeon::shoot_arrow
has a bug. If I want to shoot an arrow into3-5-9
, then I only lose one arrow. I don't think that this intended. Also, if I shoot my last arrow into a non-existent room, then I can illegally continue ;).Dungeon::move_player
has a bug, it moves the player into the wrong room. That's becauserooms
is not sorted, sorooms[target_room_number]
doesn't get you the room withroom_number == target_room_number
. Usestd::find
again :)