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
42 changes: 32 additions & 10 deletions ailp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
assert(assignment(Assignment_name)),
assert(sub_assignment(Part)).

:- % get assignment details
get_assignment_details :- % get assignment details
assignment(Assignment_name),
sub_assignment(Assignment_part),
atom_concat(Assignment_name, '_library', Assignment_library_name),
Expand Down Expand Up @@ -108,18 +108,40 @@
%
% load files and set up dependencies
( Assignment_part=0 -> use_module(assignment_library(Assignment_library_name))
; Assignment_part=1 -> use_module(assignment_library(Assignment_library_name), [map_adjacent/3,map_distance/3,agent_do_move/2,agent_do_moves/2,agent_current_energy/2,agent_current_position/2,agent_topup_energy/2,agent_ask_oracle/4,ailp_reset/0,ailp_start_position/1,part/1,shell/0,start/0,stop/0,say/1])
; Assignment_part=2 -> use_module(assignment_library(Assignment_library_name), [agent_ask_oracle/4,part/1,wp/1,wp/2,wt_link/2,actor/1,link/1,init_identity/0,test/0]),
retract(part(1)), assertz(part(2))
; Assignment_part=3 -> use_module(assignment_library('wp_library'), except([part/1,agent_ask_oracle/4])),
use_module(assignment_library(Assignment_library_name), [map_adjacent/3,map_distance/3,agent_do_move/2,agent_do_moves/2,agent_current_energy/2,agent_current_position/2,agent_topup_energy/2,agent_ask_oracle/4,ailp_reset/0,ailp_start_position/1,agent_check_oracle/2,part/1,shell/0,start/0,stop/0,say/1]),
; Assignment_part=1 -> use_module(assignment_library('wp_library')),
use_module(assignment_library(Assignment_library_name), [api_/1,part_module/1,shell/0,start/0,stop/0,
query_world/2,possible_query/2,my_agent/1,
leave_game/0,join_game/1,start_game/0,
reset_game/0,map_adjacent/3,map_distance/3,say/2]
),
find_submission('wp', WpSubmission),
load_files([assignment_root(WpSubmission)], [silent(true)])
; Assignment_part=2 -> use_module(assignment_library(Assignment_library_name), [wp/1,wp/2,wt_link/2,actor/1,link/1,
init_identity/0,test/0]
),
use_module(assignment_library('oscar_library'), [api_/1,part_module/1]),
use_module(assignment_library('game_predicates'), [agent_ask_oracle/4]),
retract(part_module(1)), assertz(part_module(2)),
game_predicates:ailp_reset
; Assignment_part=3 -> use_module(assignment_library('wp_library')),
use_module(assignment_library(Assignment_library_name), [api_/1,part_module/1,shell/0,start/0,stop/0,
query_world/2,possible_query/2,my_agent/1,
leave_game/0,join_game/1,start_game/0,
reset_game/0,map_adjacent/3,map_distance/3,say/2]
),
find_submission('wp', WpSubmission),
load_files([assignment_root(WpSubmission)], [silent(true)]),
retract(part(1)), assertz(part(3))
; Assignment_part=4 -> use_module(assignment_library('wp_library'), except([part/1,agent_ask_oracle/4])),
use_module(assignment_library(Assignment_library_name), [part/1,shell/0,start/0,stop/0,query_world/2,possible_query/2,my_agent/1,leave_game/0,join_game/1,start_game/0,reset_game/0,map_adjacent/3,map_distance/3]),
retract(part_module(1)), assertz(part_module(3))
; Assignment_part=4 -> use_module(assignment_library('wp_library')),
use_module(assignment_library(Assignment_library_name), [api_/1,part_module/1,shell/0,start/0,stop/0,
query_world/2,possible_query/2,my_agent/1,
leave_game/0,join_game/1,start_game/0,
reset_game/0,map_adjacent/3,map_distance/3,say/2]
),
find_submission('wp', WpSubmission),
load_files([assignment_root(WpSubmission)], [silent(true)]),
retract(part(1)), assertz(part(4))
retract(part_module(1)), assertz(part_module(4))
; otherwise -> true
).

:-get_assignment_details.
45 changes: 36 additions & 9 deletions ailp/library/assignment1_library.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
ailp_start_position/1, % binds with starting position p(X,Y)
ailp_show_complete/0, %
ailp_grid_size/1, % -Size
headless/1, % enable/disable visualisations
%%% moved from assignment1.pl file %%%
complete/1,
new_pos/3,
Expand All @@ -17,16 +16,44 @@
%%% re-exported from command_channel.pl %%%
reset/0,
start/0,
stop/0
stop/0,
% switches
get_switch/2,
toggle_switch/1
]
).

:- use_module('../command_channel').
:- set_homepage('mower.html').

% If headless(true) disable all do_command predicates
:- dynamic headless/1.
headless(false).
% switch
:- dynamic switch/2.

%opposite(on, off).
%opposite(off, on).
opposite(true, false).
opposite(false, true).

set_switch(S, V) :-
( opposite(V, _) -> true
; otherwise -> writeln('Switch value not available'), fail
),
retractall(switch(S,_)),
assert(switch(S,V)).

get_switch(S, V) :-
switch(S, V).

toggle_switch(S) :-
switch(S, V),
opposite(V, OV),
retractall(switch(S,_)),
assert(switch(S,OV)),
write('Switch set to: '), write(OV), write('\n').
% switch

% If switch(headless, true) disable all do_command predicates
:- set_switch(headless, false).

:- dynamic ailp_grid_size/1.
ailp_grid_size(4).
Expand All @@ -41,7 +68,7 @@
% // world in web page

ailp_show_move(p(X0,Y0),p(X1,Y1)) :-
headless(H),
switch(headless, H),
( H -> true
; (do_command([mower, colour, X0, Y0, lighter]),
do_command([mower, colour, X1, Y1, lighter]),
Expand All @@ -53,7 +80,7 @@
% (indciated by 'fail= @true' in R)

ailp_show_complete :-
headless(H),
switch(headless, H),
( H -> true
; do_command([mower, say, 'Finished!'], _R)
).
Expand Down Expand Up @@ -86,7 +113,7 @@
[mower, 6, royalblue, X,Y]
]
]),
headless(H),
switch(headless, H),
( H -> true
; do_command([mower, colour, X,Y, lighter])
).
Expand Down Expand Up @@ -130,7 +157,7 @@
\+ memberchk(P1,Ps),
ailp_show_move(P,P1),
term_to_atom([P1|Ps],PsA),
headless(H),
switch(headless, H),
( H -> true
; do_command([mower,console,PsA],_R)
),
Expand Down
Loading