Skip to content

Commit

Permalink
add solve drawings
Browse files Browse the repository at this point in the history
  • Loading branch information
Inochi Amaoto committed Mar 16, 2018
1 parent 9206163 commit b254794
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 152 deletions.
7 changes: 5 additions & 2 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ all: $(TARGETLIBS)
libkeyboard.so libcheck.so libmap_operation.so libutility.so: lib%.so: %.o
$(CC) -shared -o $@ $<

libpuzzle.so: puzzle.o libutility.so libcheck.so libmap_operation.so libsolve.so libmain.so
$(CC) -shared $(LIBSEARCH) -o libpuzzle.so puzzle.o -lutility -lcheck -lmap_operation -lsolve -lmain -lpthread
libpuzzle.so: puzzle.o libutility.so libcheck.so libmap_operation.so libsolve.so libmain.so libanalyze.so
$(CC) -shared $(LIBSEARCH) -o libpuzzle.so puzzle.o -lutility -lcheck -lmap_operation -lsolve -lanalyze -lmain -lpthread

libbuildin:
make -C ../buildin

libdefdata.so: defdata.o libbuildin
$(CC) -shared $(LIBSEARCH) -o libdefdata.so defdata.o $(DEFDATADEPEND)

libanalyze.so: analyze.o libcheck.so
$(CC) -shared $(LIBSEARCH) -o libanalyze.so analyze.o -lcheck

libmain.so libsolve.so: lib%.so: %.o libutility.so libkeyboard.so libcheck.so
$(CC) -shared $(LIBSEARCH) -o $@ $< -lkeyboard -lcheck -lutility

Expand Down
50 changes: 50 additions & 0 deletions build/analyze.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include"analyze.h"
#include"check.h"

namespace game
{
static void analyze_point_pos(
const point& __pre, const point& __now,
vector<keyboard::keyboard_mapping>& __trace
)
{
const long __d_x = static_cast<long>(__now.x-__pre.x);
const long __d_y = static_cast<long>(__now.y-__pre.y);
if(__d_x == 0)
{
if(__d_y == 1)
{ __trace.push_back(keyboard::keyboard_mapping::right_arrow);}
if(__d_y == -1)
{ __trace.push_back(keyboard::keyboard_mapping::left_arrow);}
}
if(__d_y == 0)
{
if(__d_x == 1)
{ __trace.push_back(keyboard::keyboard_mapping::down_arrow);}
if(__d_x == -1)
{ __trace.push_back(keyboard::keyboard_mapping::up_arrow);}
}
}

void analyze_point_trace(
const matrix<base_type>& __map,
const std::map<point, point>& __mapping,
const vector<point>& __po,
vector<keyboard::keyboard_mapping>& __trace
)
{
typedef vector<point>::const_iterator __iterator;
__iterator __i = __po.begin();
__iterator __j = __i;
++__i;
for(; __i != __po.end(); ++__i, ++__j)
{
if(check_is_transport(__map.at(__j->x, __j->y)))
{ analyze_point_pos(__mapping.find(*__j)->second, *__i, __trace);}
else
{ analyze_point_pos(*__j, *__i, __trace);}
}
return;
}

}
21 changes: 21 additions & 0 deletions build/analyze.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#ifndef __PUZZ_ANALYZE__
#define __PUZZ_ANALYZE__

#include"constant.hpp"
#include"matrix.hpp"
#include"structs.hpp"
#include"keyboard.h"
#include<map>

namespace game
{
void analyze_point_trace(
const matrix<base_type>& __map,
const std::map<point, point>& __mapping,
const vector<point>& __po,
vector<keyboard::keyboard_mapping>& __trace
);
}

#endif // ! __PUZZ_ANALYZE__
3 changes: 3 additions & 0 deletions build/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace game
__col > 0 && __col < __map.col();
}

bool check_is_dest(base_type __step) noexcept
{ return __step == puzz_dest;}

bool check_is_transport(base_type __step) noexcept
{ return __step == puzz_tran;}

Expand Down
8 changes: 3 additions & 5 deletions build/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@
namespace game
{
bool check_block_vaild(base_type __step) noexcept;

bool check_is_passage(base_type __step) noexcept;
bool check_is_dest(base_type __step) noexcept;
bool check_is_write_ligatures(base_type __step) noexcept;
bool check_is_transport(base_type __step) noexcept;

bool check_not_out(
unsigned long __row, unsigned long __col,
const matrix<base_type>& __map
) noexcept;

bool check_is_transport(base_type __step) noexcept;

bool check_is_write_ligatures(base_type __step) noexcept;

bool check_map_base(const matrix<base_type>& __map) noexcept;
bool check_map_wall(const matrix<base_type>& __map) noexcept;
bool check_is_mapped_vaild(const matrix<base_type>& __map) noexcept;
Expand Down
125 changes: 87 additions & 38 deletions build/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace game

namespace game
{
static void init_position(
void init_position(
const matrix<base_type>& __map, game_postion& __pos
) noexcept
{
Expand Down Expand Up @@ -106,15 +106,6 @@ namespace game
return;
}

void init_position(
const matrix<base_type>& __map,
point_mutex& __now
) noexcept
{
init_position(__map, __now.__pos);
return;
}

static void readapt_postion(
const matrix<base_type>& __map, game_postion& __pos,
const bool __row, const bool __col
Expand Down Expand Up @@ -325,9 +316,45 @@ namespace game
std::lock_guard<std::mutex> __guard(__map.__mutex);
std::lock_guard<std::mutex> __now_guard(__now.__mutex);

return __map.__data.at(__now.__pos.x, __now.__pos.y) == puzz_dest;
return check_is_dest(__map.__data.at(__now.__pos.x, __now.__pos.y));
}

void _game_playing(
countdown_mutex* __timer, mutex_puzz* __map,
const std::map<point, point>* __mapping,
point_mutex* __now,
const bool __row, const bool __col
)
{
keyboard::keyboard_mapping __dir;
while(true)
{
if(check_record())
{ return;}
__dir = keyboard::keyboard_one_step();
if(check_record())
{ return;}
move_one_step(*__map, *__now, __row, __col, *__mapping, __dir);
if(check_record())
{ return;}
if(check_is_at_dest(*__map, *__now))
{
test_out();
draw_play_matrix(*__map, *__now);
printf("You finished the game.\n\n");
return;
}
draw_play_matrix(*__map, *__now, *__timer);
if(check_record())
{ return;}
}
}

}

namespace game
{

void _time_opreator(
countdown_mutex* __timer, mutex_puzz* __map,
point_mutex* __now
Expand Down Expand Up @@ -358,35 +385,57 @@ namespace game
exit(EXIT_SUCCESS);
}

void _game_playing(
countdown_mutex* __timer, mutex_puzz* __map,
const std::map<point, point>* __mapping,
point_mutex* __now,
const bool __row, const bool __col
)
}

namespace game
{
static void delay(std::clock_t times) noexcept
{
keyboard::keyboard_mapping __dir;
while(true)
using std::clock_t;
using std::clock;
for(clock_t __now = clock(); clock() - __now < times;)
{ }
}
void show_puzzle_trace(
matrix<base_type>& __map, game_postion& __pos,
const std::map<point, point>& __mapping,
const vector<keyboard::keyboard_mapping>& __po
) noexcept
{
using std::time_t;
using std::time;

init_position(__map, __pos);

auto __use = [&__map, &__pos]()->void{
reflush_screen();
char __tmp = __map.at(__pos.x, __pos.y);
__map.at(__pos.x, __pos.y) = puzz_now;
draw_matrix(
__map, __pos.__up, __pos.__down, __pos.__left, __pos.__right
);
__map.at(__pos.x, __pos.y) = __tmp;

#ifndef NDEBUG
printf("\nNow position:(%4lu, %4lu)\n", __pos.x, __pos.y);
printf("\nNow draw position:\n");
printf("UP:\t%4lu\n", __pos.__up);
printf("DOWN:\t%4lu\n", __pos.__down);
printf("LEFT:\t%4lu\n", __pos.__left);
printf("RIGHT:\t%4lu\n", __pos.__right);
#endif // ! NDEBUG

delay(CLOCKS_PER_SEC / 10 * 3);
return;
};

__use();
const bool __row = __pos.__up != 0 || __pos.__down != __map.row();
const bool __col = __pos.__left != 0 || __pos.__right != __map.col();
for(const keyboard::keyboard_mapping& __dir: __po)
{
if(check_record())
{ return;}
__dir = keyboard::keyboard_one_step();
if(check_record())
{ return;}
move_one_step(*__map, *__now, __row, __col, *__mapping, __dir);
if(check_record())
{ return;}
if(check_is_at_dest(*__map, *__now))
{
test_out();
draw_play_matrix(*__map, *__now);
printf("You finished the game.\n\n");
return;
}
draw_play_matrix(*__map, *__now, *__timer);
if(check_record())
{ return;}
move_one_step(__map, __pos, __row, __col, __mapping, __dir);
__use();
}
}

}
7 changes: 6 additions & 1 deletion build/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace game
void init_record() noexcept;
void init_position(
const matrix<base_type>& __map,
point_mutex& __now
game_postion& __now
) noexcept;

void draw_play_matrix(
Expand All @@ -88,6 +88,11 @@ namespace game
point_mutex* __now
);

void show_puzzle_trace(
matrix<base_type>& __map, game_postion& __pos,
const std::map<point, point>& __mapping,
const vector<keyboard::keyboard_mapping>& __po
) noexcept;
}

#endif // ! __PUZZLE_MAIN_PROCESS__
Expand Down
Loading

0 comments on commit b254794

Please sign in to comment.