-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
on #30
- Loading branch information
Showing
8 changed files
with
47 additions
and
20 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
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# By: rnugroho <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2016/11/01 20:07:00 by rnugroho #+# #+# # | ||
# Updated: 2018/05/01 17:06:38 by rnugroho ### ########.fr # | ||
# Updated: 2018/05/01 17:52:39 by rnugroho ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
|
@@ -256,7 +256,7 @@ tests_vm_dump: corewar | |
@$(foreach x, $(T_VM_FILES_OP), $(MAKE) X=$x T_VM_DIR=$(T_VM_DIR_OP) test_vm_dump;) | ||
@$(foreach x, $(T_VM_FILES_HC), $(MAKE) X=$x T_VM_DIR=$(T_VM_DIR_HC) test_vm_dump;) | ||
|
||
NUMBERS = 1 20 50 80 150 200 600 800 1400 2400 5000 | ||
NUMBERS = 1 20 50 80 150 200 600 800 1400 2400 5000 8000 10000 50000 | ||
tests_vm_dump_loop: corewar | ||
@$(foreach x, $(NUMBERS), $(MAKE) DUMP=$x T_VM_DIR=$(T_VM_DIR_OP) tests_vm_dump;) | ||
|
||
|
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/19 21:39:11 by rnugroho #+# #+# */ | ||
/* Updated: 2018/05/01 15:14:01 by rnugroho ### ########.fr */ | ||
/* Updated: 2018/05/01 17:35:49 by rnugroho ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -76,6 +76,9 @@ typedef struct s_vm | |
t_champ champ[4]; | ||
int process_size; | ||
int champ_size; | ||
int last_dead_champ; | ||
int last_live_champ; | ||
int winner; | ||
} t_vm; | ||
|
||
unsigned char g_memory[MEM_SIZE]; | ||
|
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/19 21:38:33 by rnugroho #+# #+# */ | ||
/* Updated: 2018/05/01 15:46:55 by rnugroho ### ########.fr */ | ||
/* Updated: 2018/05/01 17:59:14 by rnugroho ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -100,15 +100,15 @@ int | |
vm_load_champs(&vm, g_memory); | ||
while (g_cycles == 1 || vm_checker(&vm)) | ||
{ | ||
(vm.v_lvl[V_LVL_2]) ? ft_printfln("It is now cycle %d", g_cycles) : 0; | ||
vm_decompiler(&vm); | ||
(vm.dump && vm.cycles == g_cycles) ? vm_print_memory(g_memory) : 0; | ||
(vm.v_lvl[V_LVL_0]) ? vm_print_memory_cursor(g_memory, vm) : 0; | ||
vm_executor(&vm); | ||
if (vm.v_lvl[V_LVL_1] && vm_start_ncurse(&start, vm) == -1) | ||
break ; | ||
g_cycles++; | ||
g_cycles_to++; | ||
} | ||
(!vm.dump || g_cycles < vm.cycles) ? | ||
ft_printfln("Contestant %d, \"%s\", has won !", | ||
vm.winner + 1, vm.champ[vm.winner].header.prog_name) : 0; | ||
(vm.v_lvl[V_LVL_1]) ? draw_end(&g_draw_win) : 0; | ||
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/25 12:15:39 by rnugroho #+# #+# */ | ||
/* Updated: 2018/05/01 17:15:57 by rnugroho ### ########.fr */ | ||
/* Updated: 2018/05/01 18:01:17 by rnugroho ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -50,6 +50,7 @@ void | |
p = &(((t_process*)vm->champ[i].processes->data)[j]); | ||
p->live_nbr = 0; | ||
} | ||
vm->champ[i].live_nbr = 0; | ||
} | ||
} | ||
|
||
|
@@ -109,17 +110,12 @@ int | |
vm_checker(t_vm *vm) | ||
{ | ||
int live_nbr; | ||
int winner; | ||
|
||
live_nbr = vm_checker_livenbr(*vm); | ||
if (g_cycles_to == g_cycles_to_die) | ||
{ | ||
if (vm_checker_processalive(*vm, &winner) < 1) | ||
{ | ||
(!vm->dump) ? ft_printfln("Contestant %d, \"%s\", has won !", | ||
winner + 1, vm->champ[winner].header.prog_name) : 0; | ||
if (vm_checker_processalive(*vm, &(vm->winner)) < 1) | ||
return (0); | ||
} | ||
g_cycles_to = 0; | ||
if (live_nbr > NBR_LIVE || ++g_max_check == MAX_CHECKS) | ||
{ | ||
|
@@ -131,6 +127,9 @@ int | |
vm_reset_livenbr(vm); | ||
} | ||
if (g_cycles_to_die < 0) | ||
{ | ||
vm->winner = vm->last_live_champ; | ||
return (0); | ||
} | ||
return (1); | ||
} |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/24 15:59:39 by rnugroho #+# #+# */ | ||
/* Updated: 2018/05/01 15:42:11 by rnugroho ### ########.fr */ | ||
/* Updated: 2018/05/01 17:57:45 by rnugroho ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -117,5 +117,4 @@ void | |
} | ||
} | ||
} | ||
vm_executor(vm); | ||
} |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/23 11:23:54 by rnugroho #+# #+# */ | ||
/* Updated: 2018/05/01 15:45:03 by rnugroho ### ########.fr */ | ||
/* Updated: 2018/05/01 17:59:37 by rnugroho ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -43,6 +43,7 @@ void | |
t_process *p; | ||
|
||
i = vm->champ_size - 1; | ||
vm_decompiler(vm); | ||
while (i >= 0) | ||
{ | ||
j = -1; | ||
|
@@ -59,4 +60,7 @@ void | |
} | ||
i--; | ||
} | ||
(vm->v_lvl[V_LVL_2]) ? ft_printfln("It is now cycle %d", g_cycles) : 0; | ||
(vm->dump && vm->cycles == g_cycles) ? vm_print_memory(g_memory) : 0; | ||
(vm->v_lvl[V_LVL_0]) ? vm_print_memory_cursor(g_memory, *vm) : 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/04/26 08:27:57 by fpetras #+# #+# */ | ||
/* Updated: 2018/05/01 15:10:31 by rnugroho ### ########.fr */ | ||
/* Updated: 2018/05/01 17:28:38 by rnugroho ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -27,6 +27,11 @@ void vm_op_live(t_vm *vm, t_process *p) | |
{ | ||
(void)vm; | ||
p->live_nbr++; | ||
if (p->op.params[0].value == (p->champ * -1)) | ||
{ | ||
vm->champ[p->champ].live_nbr++; | ||
vm->last_live_champ = p->champ; | ||
} | ||
vm_op_inc(vm, p); | ||
} | ||
|
||
|