Skip to content

Commit 87b74dd

Browse files
author
Yuliia DEINEHA
committed
Sat Sep 8 00:52:48 EEST 2018
1 parent 0095d53 commit 87b74dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+479
-707
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Makefile

+9-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ draw_info.c \
4141
visual_init.c \
4242
ft_itoa_base_mod.c \
4343
handle_changes.c \
44-
helpers.c
44+
helpers.c \
45+
draw_map.c
4546

4647
VERB = $(addprefix $(VERB_PATH), $(VERB_SRCS))
4748

@@ -55,23 +56,25 @@ validation.c \
5556
parse_champs.c \
5657
ft_strljoin.c \
5758
start_game.c \
59+
create_player_arr.c \
5860
create_process.c \
5961
new_process.c \
6062
conv_hex.c \
6163
run_game.c \
6264
run_processes.c \
63-
instruction_1.c \
64-
instruction_2.c \
65-
instruction_3.c \
65+
instruct_1_4.c \
66+
instruct_5_8.c \
67+
instruct_9_12.c \
68+
instruct_13_16.c \
6669
instruct_info.c \
70+
exec_instruct.c \
6771
get_codage.c \
6872
get_move.c \
6973
extract_arg.c \
7074
extract_ind.c \
7175
read_from_board.c \
7276
store_value.c \
73-
clean_all.c \
74-
print_for_debug.c \
77+
clean_all.c
7578

7679
VISU = $(addprefix $(VISU_PATH), $(VISU_SRCS))
7780

archive_verb/.DS_Store

-6 KB
Binary file not shown.

archive_verb/verb_mode.c

-44
This file was deleted.

archive_verb/verbosity.h

-50
This file was deleted.

corewar

-4.17 KB
Binary file not shown.

corewar.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef struct s_process
5252
int opcode;
5353
int cycles_to_exec;
5454
unsigned int reg[REG_NUMBER];
55+
int col;
5556
struct s_process *next;
5657
} t_process;
5758

@@ -161,7 +162,7 @@ char *ft_strljoin(char **s1, char **s2);
161162
//char *hex_line(unsigned char *line, int length);
162163
//unsigned int ft_atoi_base(char *str, long long base);
163164
void start_game(void);
164-
t_player *create_players(void);
165+
t_player *create_player_arr(void);
165166
unsigned char *create_board(t_player *player);
166167
void dump(void);
167168
t_process *create_process(t_player *player);
@@ -176,6 +177,7 @@ bool check_nbr_live(void);
176177
void run_processes(void);
177178
void exec_instruct(t_process *proc);//
178179
void read_next_instruct(t_process *proc);
180+
void read_next_pc(t_process *proc, int move, int base);
179181
// void read_next_instruct(t_process *proc, int move, int base);
180182
void exec_live(t_process *process, unsigned int *arg, t_arg_type *arg_type);
181183
void exec_ld(t_process *process, unsigned int *arg, t_arg_type *arg_type);
@@ -200,7 +202,7 @@ unsigned int *extract_arg(t_op op, int pc, t_arg_type *arg_type);
200202
unsigned int read_from_board(int pc, int length);
201203
unsigned char *extract_line(int pc, int length);
202204
unsigned int extract_ind(t_process *process, int delta, int base);
203-
bool arg_valid(t_arg_type *arg_type, unsigned int *arg, int arg_num);
205+
// bool arg_valid(t_arg_type *arg_type, unsigned int *arg, int arg_num);
204206
unsigned int arg_fin(t_process *process, unsigned int arg, t_arg_type arg_type);
205207
void store_value(t_process *proc, unsigned int value, int delta, int base);
206208
unsigned char *to_hex_str(unsigned int num);

corewar.h.gch

636 Bytes
Binary file not shown.

create_player_arr.c

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* create_player_arr.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ydeineha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2018/09/07 20:01:08 by ydeineha #+# #+# */
9+
/* Updated: 2018/09/07 20:01:10 by ydeineha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "corewar.h"
14+
15+
static void copy_info(t_player *player, t_lst_champs *tmp, int i)
16+
{
17+
player[i].num = i + 1;
18+
player[i].name = ft_strdup(tmp->name);
19+
player[i].comment = ft_strdup(tmp->comment);
20+
player[i].comms = tmp->comms;
21+
player[i].len = tmp->size;
22+
player[i].start = (MEM_SIZE / g_game.players) * i;
23+
player[i].last_live = 0;
24+
player[i].lives_in_curr = 0;
25+
player[i].lives_in_curr_all = 0;
26+
}
27+
28+
t_player *create_player_arr(void)
29+
{
30+
t_player *player;
31+
t_lst_champs *tmp;
32+
int i;
33+
34+
i = -1;
35+
if (!(player = (t_player *)malloc(sizeof(t_player) * g_game.players)))
36+
{
37+
perror("malloc() in create_players() failed ");
38+
error(-1);
39+
}
40+
while (++i < g_game.players)
41+
{
42+
tmp = g_game.champ;
43+
copy_info(player, tmp, i);
44+
g_game.champ = g_game.champ->next;
45+
free(tmp);
46+
}
47+
return (player);
48+
}

create_process.c

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ t_process *create_process(t_player *player)
2424
while (i < g_game.players)
2525
{
2626
tmp = new_process(&player[i], NULL, player[i].start);
27+
tmp->col = -1;
2728
add_process(&proc, tmp);
2829
i++;
2930
}

exec_instruct.c

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* exec_instruct.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: ydeineha <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2018/09/07 19:00:54 by ydeineha #+# #+# */
9+
/* Updated: 2018/09/07 19:00:56 by ydeineha ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "corewar.h"
14+
15+
static t_arg_type *get_arg_type(t_process *proc)
16+
{
17+
t_arg_type *arg_type;
18+
t_op op;
19+
20+
arg_type = NULL;
21+
op = g_op_tab[proc->opcode - 1];
22+
if (op.codage)
23+
arg_type = get_codage(proc, op.arg_num);
24+
else
25+
{
26+
arg_type = ft_strnew(op.arg_num);
27+
ft_memcpy(arg_type, op.arg, op.arg_num);
28+
}
29+
return (arg_type);
30+
}
31+
32+
static bool arg_valid(t_arg_type *arg_type,
33+
unsigned int *arg, int arg_num)
34+
{
35+
int i;
36+
37+
i = 0;
38+
while (i < arg_num)
39+
{
40+
if (arg_type[i] == T_REG &&
41+
(arg[i] == 0 || arg[i] > 16))
42+
return (0);
43+
i++;
44+
}
45+
return (1);
46+
}
47+
48+
void exec_instruct(t_process *proc)
49+
{
50+
t_arg_type *arg_type;
51+
int move;
52+
unsigned int *arg;
53+
t_op op;
54+
int base;
55+
56+
op = g_op_tab[proc->opcode - 1];
57+
arg_type = get_arg_type(proc);
58+
arg = NULL;
59+
base = (proc->opcode == 9 && proc->carry) ? IDX_MOD : MEM_SIZE;
60+
if (!op.codage || (op.codage && codage_valid(arg_type, op.arg, op.arg_num)))
61+
{
62+
arg = extract_arg(op, proc->pc, arg_type);
63+
if (arg_valid(arg_type, arg, op.arg_num))
64+
{
65+
if (g_game.v && !g_game.visu && proc->opcode != 16)
66+
verb_print_op(proc, arg_type, arg);
67+
g_command[proc->opcode - 1](proc, arg, arg_type);
68+
}
69+
}
70+
move = get_move(proc, arg_type, arg);
71+
read_next_pc(proc, move, base);
72+
arg_type ? free(arg_type) : 0;
73+
arg ? free(arg) : 0;
74+
}

instruction_3.c instruct_13_16.c

+3-39
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,17 @@
11
/* ************************************************************************** */
22
/* */
33
/* ::: :::::::: */
4-
/* instruction_3.c :+: :+: :+: */
4+
/* instruct_13_16.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
66
/* By: ydeineha <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
8-
/* Created: 2018/09/05 21:30:13 by ydeineha #+# #+# */
9-
/* Updated: 2018/09/05 21:30:16 by ydeineha ### ########.fr */
8+
/* Created: 2018/09/07 18:30:27 by ydeineha #+# #+# */
9+
/* Updated: 2018/09/07 18:30:29 by ydeineha ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "corewar.h"
1414

15-
void exec_sti(t_process *process, unsigned int *arg, t_arg_type *arg_type)
16-
{
17-
int value;
18-
int delta;
19-
int arg_2;
20-
int arg_3;
21-
22-
value = arg_fin(process, arg[0], arg_type[0]);
23-
arg_2 = arg_fin(process, arg[1], arg_type[1]);
24-
arg_3 = arg_fin(process, arg[2], arg_type[2]);
25-
if (arg_type[1] == T_DIR && arg_type[2] == T_DIR)
26-
delta = (short)arg_2 + (short)arg_3;
27-
else if (arg_type[1] == T_DIR)
28-
delta = (short)arg_2 + arg_3;
29-
else if (arg_type[2] == T_DIR)
30-
delta = arg_2 + (short)arg_3;
31-
else
32-
delta = arg_2 + arg_3;
33-
store_value(process, value, delta, IDX_MOD);
34-
}
35-
36-
void exec_fork(t_process *process, unsigned int *arg, t_arg_type *arg_type)
37-
{
38-
int delta;
39-
int pc;
40-
t_process *new;
41-
42-
new = NULL;
43-
delta = arg_fin(process, arg[0], arg_type[0]);
44-
pc = (process->pc + ((short)delta % IDX_MOD)) % MEM_SIZE;
45-
if (pc < 0)
46-
pc += MEM_SIZE;
47-
new = new_process(NULL, process, pc);
48-
add_process(&(g_game.proc), new);
49-
}
50-
5115
void exec_lld(t_process *process, unsigned int *arg, t_arg_type *arg_type)
5216
{
5317
int res;

0 commit comments

Comments
 (0)