1人プレイの相手をしてくれるAIをJavaScriptで作ってみました。
将棋AIのゲーム木を評価関数で数値化する方式を真似して、AI側の行動のゲーム木を評価関数で数値化します。
ソースはこんな感じです。→ソース
AIと対戦してみる(モード選択で「SinglePlay」を選ぶとAIが対戦相手になってくれます。)
 
 
 
// enchant.jsの表示をセンタリング
var moveStageToCenter = function(core) {
 var stagePos = {
  top: (window.innerHeight - (core.height * core.scale)) / 2,
  left: (window.innerWidth - (core.width * core.scale)) / 2,
 };
 var stage = document.getElementById('enchant-stage');
 stage.style.position = 'absolute';
 stage.style.top = stagePos.top + 'px';
 stage.style.left = stagePos.left + 'px';
 core._pageX = stagePos.left;
 core._pageY = stagePos.top;
};
body {
 background-image: url(./img/hexabump.png);
 background-repeat: repeat;
}
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NullCheck1D
{
    class Program
    {
        static void Main(string[] args)
        {
            // チェック対象の配列
            Object[] testArray1D = { new object(), new object(), null, new object() };
            // nullの存在をチェック
            if (Array.IndexOf(testArray1D, null) > -1)
            {
                Console.WriteLine("nulあり");
            }
            else
            {
                Console.WriteLine("nulなし");
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// 多次元配列のnullチェック
/// </summary>
namespace NullCheck2D
{
    class Program
    {
        static void Main(string[] args)
        {
            // チェック対象の配列配列(2次元配列)
            //   ([,]は[2,2]を省略した書き方です)
            Object[,] testArray2D = new Object[,]
            {
                { new Object(), new Object() },
                { null, new Object() }
            };
            // nullの存在をチェック
            if (hasNull(testArray2D))
            {
                Console.WriteLine("nulあり");
            }
            else
            {
                Console.WriteLine("nulなし");
            }
        }
        /// <summary>
        /// 配列のnullチェック
        /// </summary>
        /// <param name="target">チェック対象の配列</param>
        /// <returns>true=nullあり / false=nullなし</returns>
        static bool hasNull(Array target)
        {
            foreach (Object element in target)
            {
                if (element == null)
                {
                    return true;
                }
            }
            return false;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// 配列のnullチェック(1次元配列、多次元配列、ジャグ配列)
/// </summary>
namespace NullCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            // チェック対象の配列(2次元+ジャグ)
            Object[,] testArray = new Object[,]
            {
                { new Object(), new Object() },
                { new Object[] { new Object(), null }, new Object() }
            };
            // nullの存在をチェック
            if (hasNull(testArray))
            {
                Console.WriteLine("nulあり");
            }
            else
            {
                Console.WriteLine("nulなし");
            }
        }
        /// <summary>
        /// 配列のnullチェック
        /// </summary>
        /// <param name="target">チェック対象の配列</param>
        /// <returns>true=nullあり / false=nullなし</returns>
        static bool hasNull(Array target)
        {
            foreach (Object element in target)
            {
                if (element == null)
                {
                    return true;
                }
                if (element.GetType().IsArray)
                {
                    //要素が配列の場合は、この配列チェック関数に再帰
                    if (hasNull((Array)element))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
    }
}