Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions include/stalker320/common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __common_h
#define __common_h

#define _Consume

#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

Expand Down
10 changes: 4 additions & 6 deletions include/stalker320/field/applicant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
#define __applicant_h

#include <stdbool.h>
#define _Consume
#define PROGRAM_LENGTH 256
#define MEMORY_CAPACITY 32

#include <stalker320/common.h>
#include <stdint.h>
typedef struct applicant applicant;
typedef unsigned char buffsz_t;
typedef
Expand Down Expand Up @@ -50,8 +48,8 @@ void applicantConnectBuffer(applicant* applicant, unsigned char* buffer, buffsz_
void applicantSetFlushCallback(void* caller, applicant* applicant, void (*flushcallback)(void* restrict receiver, struct applicant* restrict _applicant, int index));

unsigned char applicantGetTop(applicant* applicant);
unsigned char applicantGetMemoryCursor(applicant* applicant);
unsigned char applicantGetProgramCursor(applicant* applicant);
uint32_t applicantGetMemoryCursor(applicant* applicant);
uint32_t applicantGetProgramCursor(applicant* applicant);
unsigned char applicantGetProgramAt(applicant* applicant, char at);
unsigned char applicantGetMemoryAt(applicant* applicant, char at);
unsigned char applicantGetHeatAt(applicant* applicant, char at);
Expand Down
7 changes: 4 additions & 3 deletions include/stalker320/field/bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ bool botIsAlive(struct bot* bot);
unsigned char botGetHp(struct bot* bot);
unsigned char botGetHunger(struct bot* bot);
int botGetSteps(struct bot* bot);
unsigned char botGetApplicantAccum(bot* bot);

unsigned char botGetApplicantTop(bot* bot);
unsigned char botGetApplicantMemoryCursor(bot* bot);
unsigned char botGetOutputBuffer(bot* bot, int idx);
unsigned char botGetApplicantProgramCursor(bot* bot);

uint32_t botGetApplicantMemoryCursor(bot* bot);
uint32_t botGetApplicantProgramCursor(bot* bot);
unsigned char botGetApplicantProgramAt(bot* bot, int idx);
unsigned char botGetApplicantMemoryAt(bot* bot, int idx);
unsigned char botGetApplicantHeatAt(bot* bot, int idx);
Expand Down
2 changes: 2 additions & 0 deletions include/stalker320/field/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __config_h
#define __config_h

#define PROGRAM_LENGTH 1024
#define MEMORY_CAPACITY 64

#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
Expand Down
10 changes: 7 additions & 3 deletions src/applicant.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stalker320/common.h>
#include <stalker320/field/config.h>
#include <stalker320/field/applicant.h>
#include <ncurses.h>
#include <stdint.h>
Expand All @@ -20,7 +21,7 @@ struct applicantContent {
struct applicant {
struct applicantContent content;
uint8_t memory[MEMORY_CAPACITY];
unsigned char programCursor, memoryCursor;
uint32_t programCursor, memoryCursor;
unsigned char bufferCount;
struct applicantFlags flags;
int generation;
Expand Down Expand Up @@ -82,6 +83,9 @@ applicant* createApplicant(applicant* src, bool mutate, bool zero) {
if (src->content.heat[i] < 0x1F) {
applicant->content.heat[i] = src->content.heat[i];
}
else {
applicant->content.heat[i] = src->content.heat[i] / 2;
}
}

}
Expand Down Expand Up @@ -144,11 +148,11 @@ unsigned char applicantGetTop(applicant* applicant) {
if (!applicant) return 0x00;
return applicant->memory[(applicant->memoryCursor - 1) % MEMORY_CAPACITY];
}
unsigned char applicantGetMemoryCursor(applicant* applicant) {
uint32_t applicantGetMemoryCursor(applicant* applicant) {
if (!applicant) return 0x00;
return applicant->memoryCursor % MEMORY_CAPACITY;
}
unsigned char applicantGetProgramCursor(applicant* applicant) {
uint32_t applicantGetProgramCursor(applicant* applicant) {
if (!applicant) return 0x00;
return applicant->programCursor % PROGRAM_LENGTH;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ unsigned char botGetApplicantTop(bot* bot) {
if (!bot) return 0x00;
return applicantGetTop(bot->applicant);
}
unsigned char botGetApplicantMemoryCursor(bot* bot) {
uint32_t botGetApplicantMemoryCursor(bot* bot) {
if (!bot) return 0x00;
return applicantGetMemoryCursor(bot->applicant);
}
unsigned char botGetOutputBuffer(bot* bot, int idx) {
if (!bot) return 0x00;
return bot->outputBuffer[idx % 1];
}
unsigned char botGetApplicantProgramCursor(bot* bot) {
uint32_t botGetApplicantProgramCursor(bot* bot) {
if (!bot) return 0x00;
return applicantGetProgramCursor(bot->applicant);
}
Expand Down
Loading