Skip to content

Instantly share code, notes, and snippets.

public class OnlinePurchase extends PurchaseProcessTemplate {
@Override
public void doSelectItems() {
System.out.println("The customer selects items and adds them to a shopping basket.");
}
@Override
public void doPurchaseItems() {
System.out.println("The customer adds their delivery address and card details when checking out.");
}
public class InStorePurchase extends PurchaseProcessTemplate {
@Override
public void doSelectItems() {
System.out.println("Customer selects items from the rack.");
}
@Override
public void doPurchaseItems() {
System.out.println("Customer pays for items at the counter.");
public abstract class PurchaseProcessTemplate {
public final void processPurchase() {
greetCustomer();
doSelectItems();
doPurchaseItems();
doDeliverItems();
thankCustomer();
}
public class VideoPlayer implements MediaPlayer{
private String videoName;
private boolean isPlaying = false;
public VideoPlayer(String videoName) {
this.videoName = videoName
}
@Override
public void play() {
public class MusicPlayer implements MediaPlayer{
private String songName;
private boolean isPlaying = false;
public MusicPlayer(String songName) {
this.songName = songName
}
@Override
public void play() {
public interface MediaPlayer {
void play();
void stop();
void currentlyPlaying();
}
available_squares.each do |square|
board.player_make_move(current_player, square)
best_score[square] =
-1 * find_best_move(board, depth + 1, opponent, current_player)
board.reset_square(square)
end
def evaluate_move(depth, scores)
depth.zero? ? max_best_move(scores) : max_best_score(scores)
end
def max_best_move(scores)
scores.max_by { |_key, value| value }[0]
end
def max_best_score(scores)
scores.max_by { |_key, value| value }[1]
class Minimax
def choose_move(board, current_player, opponent)
copy_board = board.copy_board
find_best_move(copy_board, current_player, opponent)
end
private
def find_best_move(board, depth=0, current_player, opponent)
def score_move(board, depth, current_player, opponent)
if board.winning_line?(current_player)
10 - depth
elsif board.winning_line?(opponent)
depth - 10
elsif board.complete?
0
end
end