Skip to content

Instantly share code, notes, and snippets.

@smd877
Created January 8, 2020 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smd877/ed67e8e11a7f7ef84f447424cb4f1568 to your computer and use it in GitHub Desktop.
Save smd877/ed67e8e11a7f7ef84f447424cb4f1568 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<header>
<div class="navbar navbar-dark bg-dark">
<div class="container">
<span class="navbar-brand">
<strong>5連個体値チェッカー 3Vのみ対応</strong>
</span>
</div>
</div>
</header>
<div class="container">
<div class="py-2"></div>
<form>
<div class="form-group row">
<label for="paramH" class="col-sm-1 col-form-label text-right">H</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="paramH" name="paramH" value="" />
</div>
</div>
<div class="form-group row">
<label for="paramA" class="col-sm-1 col-form-label text-right">A</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="paramA" name="paramA" value="" />
</div>
</div>
<div class="form-group row">
<label for="paramB" class="col-sm-1 col-form-label text-right">B</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="paramB" name="paramB" value="" />
</div>
</div>
<div class="form-group row">
<label for="paramC" class="col-sm-1 col-form-label text-right">C</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="paramC" name="paramC" value="" />
</div>
</div>
<div class="form-group row">
<label for="paramD" class="col-sm-1 col-form-label text-right">D</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="paramD" name="paramD" value="" />
</div>
</div>
<div class="form-group row">
<label for="paramS" class="col-sm-1 col-form-label text-right">S</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="paramS" name="paramS" value="" />
</div>
</div>
<div class="form-group row">
<div class="col-sm-1"></div>
<div class="col-sm-2">
<a href="#" onclick="check()" class="btn btn-success">チェック</a>
</div>
</div>
<div class="form-group row">
<div class="col-sm-1"></div>
<p class="col-sm-3" id="result"></p>
</div>
</form>
</div>
<script>
// 確認処理
function check() {
// 結果表示用の文字列変数
var msg = null;
// 再計算対象位置の箱
var ary_recalc_y = [];
// 再計算非対象位置の箱
var ary_recalc_n = [];
// 個体値の箱
var ary_nums = [];
// H-Sの各個体値を入れた箱
var ary_params = [];
ary_params.push($("#paramH").val());
ary_params.push($("#paramA").val());
ary_params.push($("#paramB").val());
ary_params.push($("#paramC").val());
ary_params.push($("#paramD").val());
ary_params.push($("#paramS").val());
// formの入力値からH-Sの各個体値が正しく入力されているか確認
$.each(ary_params, function(i, value){
// 入力値に問題ないか
var ret = check_input_number(value);
// 文字列で返却されていたら入力値不正
if (isNaN(ret)) {
msg = ret;
return false;
}
if (ret == 31) {
// 入力値がVならary_recalc_yにパラメータ位置追加(Hなら0、Aなら1、、、)
ary_recalc_y.push(i);
} else {
// 入力値がV以外ならary_recalc_nにパラメータ位置追加
ary_recalc_n.push(i);
// V以外の個体値なので値をary_numsに入力
ary_nums.push(ret);
}
})
// ここまででエラーなら処理中断
if (msg != null) {
put_msg(msg);
return;
}
// V固定数は3だけにしています
if (ary_recalc_y.length != 3) {
put_msg("Vの個数は3になるようにしてね。");
return;
}
// 6と7は再計算対象なのでary_recalc_yに追加
ary_recalc_y.push(6);
ary_recalc_y.push(7);
// V以外の個体値からパズル可能か算出
$.each(ary_nums, function(i, value){
// 次のV位置は個体値÷8の余りから決定される
var mid = value % 8;
// 3Vの場合、1,2回目は再計算対象、3回目は非対象の配列を使用。
var array = ((i + 1) < 3) ? ary_recalc_y : ary_recalc_n;
// 対象の配列にmidが含まれていたら処理続行
if (array.indexOf(mid) != -1) {
return true;
} else {
// 含まれていなければパズルNG
msg = "パズルNGです。";
return false;
}
})
// ここまででエラーなら処理中断
if (msg != null) {
put_msg(msg);
return;
}
// 処理終わり
put_msg("パズルOKです。");
return;
}
// メッセージ出す処理。雑。
function put_msg(msg) {
$("#result").text(msg);
}
// 入力値の確認処理
function check_input_number(val) {
// 未入力
if ("" == val) {
return "未入力があるよ。";
}
// 数字じゃない
if (isNaN(val)) {
return "数字で入れてね。";
}
var num = Number(val);
// 個体値が0~31の範囲から違反
if (num < 0 || num > 31) {
return "範囲は0-31で入れてね。";
}
// 問題なければ数値化した入力値を返却
return num;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment