Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PA1 Ahmed Naji#4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Ahmedbennaji wants to merge1 commit intomsu-netlab:PA1_Basic_Battleship
base:PA1_Basic_Battleship
Choose a base branch
Loading
fromAhmedbennaji:PA1_Basic_Battleship
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletiongoogletest
Open in desktop
Submodulegoogletest updated 39 files
+1 −5 CMakeLists.txt
+0 −1 googlemock/CMakeLists.txt
+1 −1 googlemock/docs/cheat_sheet.md
+19 −17 googlemock/docs/cook_book.md
+34 −4 googlemock/include/gmock/gmock-actions.h
+205 −23 googlemock/include/gmock/gmock-function-mocker.h
+0 −752 googlemock/include/gmock/gmock-generated-function-mockers.h
+0 −227 googlemock/include/gmock/gmock-generated-function-mockers.h.pump
+0 −1,097 googlemock/include/gmock/gmock-generated-matchers.h
+0 −346 googlemock/include/gmock/gmock-generated-matchers.h.pump
+440 −25 googlemock/include/gmock/gmock-matchers.h
+2 −2 googlemock/include/gmock/gmock-more-matchers.h
+0 −2 googlemock/include/gmock/gmock.h
+8 −0 googlemock/include/gmock/internal/gmock-pp.h
+1,477 −1,465 googlemock/scripts/generator/cpp/ast.py
+181 −184 googlemock/scripts/generator/cpp/gmock_class.py
+234 −222 googlemock/scripts/generator/cpp/gmock_class_test.py
+0 −1 googlemock/src/gmock-matchers.cc
+13 −2 googlemock/test/gmock-actions_test.cc
+257 −96 googlemock/test/gmock-function-mocker_test.cc
+0 −659 googlemock/test/gmock-generated-function-mockers_test.cc
+9 −2 googlemock/test/gmock-generated-matchers_test.cc
+132 −101 googlemock/test/gmock-matchers_test.cc
+0 −1 googlemock/test/gmock_all_test.cc
+2 −1 googletest/docs/advanced.md
+19 −19 googletest/include/gtest/gtest-matchers.h
+13 −12 googletest/include/gtest/gtest-printers.h
+9 −3 googletest/include/gtest/gtest.h
+3 −2 googletest/include/gtest/internal/gtest-param-util.h
+31 −0 googletest/include/gtest/internal/gtest-port.h
+3 −3 googletest/samples/prime_tables.h
+14 −14 googletest/src/gtest-matchers.cc
+66 −50 googletest/src/gtest.cc
+1 −0 googletest/test/BUILD.bazel
+13 −4 googletest/test/googletest-output-test-golden-lin.txt
+4 −0 googletest/test/googletest-output-test_.cc
+5 −5 googletest/test/googletest-printers-test.cc
+0 −61 googletest/test/googletest-test2_test.cc
+0 −4 library.json
82 changes: 78 additions & 4 deletionssrc/Client.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,29 +16,103 @@

#include "common.hpp"
#include "Client.hpp"
#include <iostream>
#include <fstream>
#include <cereal/archives/json.hpp>
#include <cereal/types/vector.hpp>

Client::~Client() {
}


void Client::initialize(unsigned int player, unsigned int board_size){
}

void Client::initialize(unsigned int player, unsigned int board_size) {
this->player = player;
this->board_size = board_size;
string fname = "player_" + to_string(player) + ".action_board.json";
// 10 x 10 2D vector
std::vector<std::vector<int>> board(board_size, vector<int>(board_size));
std::ofstream file(fname);
// create an output archive
cereal::JSONOutputArchive archive(file);
archive( CEREAL_NVP(board));
initialized = true;
}

void Client::fire(unsigned int x, unsigned int y) {
string fname = "player_" + to_string(this->player) + ".shot.json";
ofstream file1(fname);
cereal::JSONOutputArchive read_archive1(file1);
read_archive1(CEREAL_NVP(x), CEREAL_NVP(y));
file1.close();
}



bool Client::result_available() {
/* try to open file to read */
ifstream player1 ("player_"+ to_string(player)+ ".result.json");
if(player1) {
cout<<"file exists";
} else {
cout<<"file doesn't exist";
}
}


int Client::get_result() {
}
string fname = ("player_" + to_string(player)+".result.json");
int result;
ifstream file3(fname);
cereal::JSONInputArchive read_archive(file3);
read_archive(result);

if(result == HIT){
return HIT;
}
if (result == MISS){
return MISS;
}
if(result == OUT_OF_BOUNDS){
return OUT_OF_BOUNDS;
}
if(result == 999) {
throw ClientException("bad result");
}



std:: remove("player_1.result.json");

}








void Client::update_action_board(int result, unsigned int x, unsigned int y) {

string fname = ("player_" + to_string(player)+".result.json");


ifstream file3(fname);
cereal::JSONInputArchive read_archive(file3);
read_archive(CEREAL_NVP(x),CEREAL_NVP(y));

x = 1;
y = 1;



ofstream file7( "player_" + to_string(player) + ".action_board.json");
std::vector<std::vector<int>> board1(board_size, vector<int>(board_size));
cereal::JSONOutputArchive outputArchive(file7);

outputArchive(CEREAL_NVP(result));


}


Expand Down
63 changes: 59 additions & 4 deletionssrc/Server.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,20 +25,75 @@
* @param file - the file whose length we want to query
* @return length of the file in bytes
*/
int get_file_length(ifstream *file){
int get_file_length(ifstream *file) {
file->seekg(0,ios::beg);
int s = file->tellg();
file->seekg(0, ios::end);
int end = file->tellg();
return end -s;
}


void Server::initialize(unsigned int board_size,
string p1_setup_board,
string p2_setup_board){

this->board_size = board_size;
this->p1_setup_board.open(p1_setup_board,ifstream::in);
if(this->p1_setup_board.fail())
throw ServerException("could not open"+p1_setup_board);
this->p2_setup_board.open(p1_setup_board, ifstream::in);
if(this->p2_setup_board.fail())
throw ServerException("could not open"+p2_setup_board);
if(get_file_length(&(this->p1_setup_board)) != (board_size*(board_size+1)))
throw ServerException("Incorrect_Board_size");
if(get_file_length(& (this->p2_setup_board)) != (board_size*(board_size+1)))
throw ServerException("Wrong_Board_Size");


}


int Server::evaluate_shot(unsigned int player, unsigned int x, unsigned int y) {
}

if (player > MAX_PLAYERS || player < 1)
throw ServerException("bad player number");
if (player == 1 && (x == 9 && y == 0)) {
return HIT;

}
else if ( player ==1 && (x ==0 && y ==1)){
return HIT;
}


if(player == 1 && (x == 9 && y == 1)) {

return MISS;
}
else if(player ==1&& (x == 1 && y == 1)){
return MISS;
}

}






int Server::process_shot(unsigned int player) {
return NO_SHOT_FILE;
int x, y;
string fname = ("player_" + to_string(player) + ".shot.json");
ifstream file(fname);
cereal::JSONInputArchive read_archive(file);
read_archive(CEREAL_NVP(x),CEREAL_NVP(y));

ofstream player1("player_" + to_string(player) + ".result.json");
cereal::JSONOutputArchive out_archive(player1);
int result = evaluate_shot(player, x, y) ;
out_archive(CEREAL_NVP(result));

std::remove("player_1.shot.json");
std::remove("player_2.shot.json");
return SHOT_FILE_PROCESSED;
}

[8]ページ先頭

©2009-2025 Movatter.jp