forked from mr-andreas/neuralnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6209004
commit 2226161
Showing
8 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
project(neuralnet) | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
add_executable(neuralnet main.cpp) | ||
FILE(GLOB MyCSources *.cpp) | ||
|
||
ADD_EXECUTABLE(neuralnet ${MyCSources}) | ||
|
||
install(TARGETS neuralnet RUNTIME DESTINATION bin) | ||
|
||
target_link_libraries(neuralnet SDL SDL_image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "gamestate.h" | ||
|
||
#include <stdlib.h> | ||
|
||
Sweeper::Sweeper() { | ||
int posx = 0; | ||
int posy = 0; | ||
} | ||
|
||
Gamestate::Gamestate(int boardWidth, int boardHeight) { | ||
this->boardWidth = boardWidth; | ||
this->boardHeight = boardHeight; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef _GAMESTATE_H | ||
#define _GAMESTATE_H | ||
|
||
#include <vector> | ||
|
||
class Sweeper { | ||
public: | ||
Sweeper(); | ||
|
||
int posx, posy; | ||
}; | ||
|
||
class Gamestate { | ||
public: | ||
Gamestate(int boardWidth, int boardHeight); | ||
|
||
int boardWidth, boardHeight; | ||
|
||
std::vector<Sweeper> sweepers; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "gfx.h" | ||
|
||
const char* WINDOW_TITLE = "SDL Start"; | ||
|
||
void plotSweeper(sdlgamestate_t *g, const Sweeper &sweeper) { | ||
// Part of the bitmap that we want to draw | ||
SDL_Rect source; | ||
source.x = 0; | ||
source.y = 0; | ||
source.w = 65; | ||
source.h = 44; | ||
|
||
// Part of the screen we want to draw the sprite to | ||
SDL_Rect destination; | ||
destination.x = sweeper.posx; | ||
destination.y = sweeper.posy; | ||
destination.w = 65; | ||
destination.h = 44; | ||
|
||
SDL_BlitSurface(g->bitmaps.sweeper, &source, g->screen, &destination); | ||
} | ||
|
||
void plotSweepers(sdlgamestate_t *g) { | ||
const std::vector<Sweeper> &s(g->gamestate->sweepers); | ||
|
||
for(std::vector<Sweeper>::const_iterator i = s.begin(); i != s.end(); i++) { | ||
plotSweeper(g, *i); | ||
} | ||
} | ||
|
||
void init(sdlgamestate_t *g) { | ||
SDL_Init( SDL_INIT_VIDEO ); | ||
|
||
g->screen = SDL_SetVideoMode( | ||
g->gamestate->boardWidth, g->gamestate->boardHeight, 0, SDL_HWSURFACE | SDL_DOUBLEBUF | ||
); | ||
SDL_WM_SetCaption( WINDOW_TITLE, 0 ); | ||
|
||
g->bitmaps.sweeper = IMG_Load("/home/ante/dev/neuralnet/res/sweeper.png"); | ||
if(!g->bitmaps.sweeper) { | ||
printf("No bitmap :(\n"); | ||
exit(1); | ||
} | ||
} | ||
|
||
int sdlMainLoop(sdlgamestate_t *g) { | ||
init(g); | ||
|
||
SDL_Event event; | ||
bool gameRunning = true; | ||
|
||
while (gameRunning) { | ||
if (SDL_PollEvent(&event)) { | ||
if (event.type == SDL_QUIT) { | ||
gameRunning = false; | ||
} | ||
} | ||
|
||
plotSweepers(g); | ||
|
||
SDL_Flip(g->screen); | ||
} | ||
|
||
SDL_FreeSurface(g->bitmaps.sweeper); | ||
SDL_Quit(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef _GFX_H | ||
#define _GFH_H | ||
|
||
#include <SDL/SDL.h> | ||
#include <SDL/SDL_image.h> | ||
|
||
#include "gamestate.h" | ||
|
||
typedef struct { | ||
Gamestate *gamestate; | ||
|
||
SDL_Surface *screen; | ||
struct { | ||
SDL_Surface *sweeper; | ||
} bitmaps; | ||
|
||
|
||
} sdlgamestate_t; | ||
|
||
int sdlMainLoop(sdlgamestate_t *g); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
int main(int argc, char **argv) { | ||
#include "gfx.h" | ||
|
||
using namespace std; | ||
|
||
typedef struct { | ||
int inputCount; | ||
|
||
unsigned int threshold; | ||
unsigned int weights[4]; | ||
} neuron_t; | ||
|
||
int oldmain(int argc, char **argv) { | ||
neuron_t hiddenLayer[4]; | ||
neuron_t outputLayer[2]; | ||
|
||
std::cout << "Hello, world!" << std::endl; | ||
return 0; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
sdlgamestate_t g; | ||
Gamestate gs(640, 480); | ||
g.gamestate = &gs; | ||
|
||
gs.sweepers.push_back(Sweeper()); | ||
|
||
return sdlMainLoop(&g); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.