/////////////////////////////////////////////////////////////////////////
// Copyright (c) 2015 Something Precious, Inc.
//
// BasicDecisionMaker.cs: DecisionMaker C^tF[XÌî{À
//
// Author:      Shin-ya Koga (koga@stprec.co.jp)
// Created:     Jan. 12, 2015
// Last update: Jul. 31, 2015
/////////////////////////////////////////////////////////////////////////

using System.Collections.Generic;


namespace CHaser
{
public class BasicDecisionMaker : DecisionMaker {
    // RXgN^
    public BasicDecisionMaker() {}

// ñöJ\bh
    // DecisionMaker C^tF[XÌÀ
    protected override List<IActionSelector> CreateActionSelectors()
    {
        List<IActionSelector>    selectors = new List<IActionSelector>(3);

        selectors.Add(new AdjacentCharacter());
        selectors.Add(new AdjacentBlock());
        selectors.Add(new AdjacentItem());
        selectors.Add(new PreferFirstTime());

        return selectors;
    }

    // îêNXÌUé¢ÌJX^}CY
        // ÅIóâÌIð
    protected override void SelectFinalCandidate(
        List<Command> ioCandidates, FloorMap map)
    {
        if (null != mLastAction) {
            // OñÀsµ½ANVªñÚ®ÌêA¡ñà¯¶©`FbN
            if (!mLastAction.IsWalk && mLastAction == ioCandidates[0]) {
                // ¯¶êAÚ®ANVðIðÂ\ÈçIð
                foreach (Command c in ioCandidates) {
                    if (c.IsWalk) {
                        ioCandidates.Clear();
                        ioCandidates.Add(c);
                        return;  // ©Â©Á½
                    }
                }
            } else if (mLastAction.IsWalk && !ioCandidates[0].IsWalk
                && !ioCandidates[0].IsPut) {
                // OñÀsµ½ANVªÚ®ÅA¡ñÍTõªóâÌêÍ²®
                foreach (Command c in ioCandidates) {
                    if (mLastAction.GetDir() == c.GetDir()) {
                        ioCandidates.Clear();
                        ioCandidates.Add(c);
                        return;  // ©Â©Á½
                    }
                }
            }
        }

        // ftHgÅÍîêNXÆ¯¶Ué¢
        base.SelectFinalCandidate(ioCandidates, map);
    }
}
}

//
// End of File
//
