Commit 12e22ec6 authored by 18손재민's avatar 18손재민

한글 자모를 이용한 편집 거리 구하는 함수 구현 wip

parent ece8a72e
var GameServer = GameServer || {};
GameServer.Phase = {READY: 0, START: 1, MAIN: 2, MUSIC: 3};
GameServer.startCount = 5;
GameServer.startCount = 1;
GameServer.currentPlayer = [];
GameServer.playingRoom = [];
......
......@@ -146,13 +146,13 @@ class AttackWord extends WordObject
class NameWord extends WordObject
{
constructor(name, _isStrong = false)
constructor(player, _isStrong = false)
{
super(name.nickname);
this.ownerId = name.id;
super(player.nickname);
this.ownerId = player.id;
this.wordWeight = 2;
this.isStrong = _isStrong;
console.log('Name : ' + name.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight);
console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight);
}
destroy()
{
......
var WordReader = WordReader || {};
//초성의 타수를 반환함
function firstSound(charText)
WordReader.firstSound = function(charText)
{
var r = parseInt(((charText.charCodeAt(0) - parseInt('0xac00',16)) /28) / 21);
//쌍자음일 경우
......@@ -10,7 +10,7 @@ function firstSound(charText)
}
//중성의 타수를 반환함
function middleSound(charText)
WordReader.middleSound = function(charText)
{
var r = parseInt(((charText.charCodeAt(0)- parseInt('0xac00',16)) / 28) % 21);
//'ㅒ' 또는 'ㅖ'일 경우
......@@ -21,7 +21,7 @@ function middleSound(charText)
}
//종성의 타수를 반환함
function lastSound(charText)
WordReader.lastSound = function(charText)
{
var r = parseInt((charText.charCodeAt(0) - parseInt('0xac00',16)) % 28);
//쌍자음일 경우
......@@ -40,7 +40,7 @@ WordReader.getWordTyping = function(stringText)
for(var i = 0; i < stringText.length; i++)
{
if(stringText.charCodeAt(i) < parseInt('0xac00',16) || stringText.charCodeAt(i) > parseInt('0xd7af',16)) return -1;
temp += parseFloat(firstSound(stringText.charAt(i))) + middleSound(stringText.charAt(i)) + lastSound(stringText.charAt(i));
temp += parseFloat(WordReader.firstSound(stringText.charAt(i))) + WordReader.middleSound(stringText.charAt(i)) + WordReader.lastSound(stringText.charAt(i));
}
return temp;
}
......
......@@ -70,7 +70,7 @@ WordSpace.gameOverCycle = new Cycle(gameOver);
//호패 생성 사이클
WordSpace.nameCycle = new Cycle(function()
{
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
//WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
});
//이건 뭐지
WordSpace.varAdjustCycle = new Cycle(function()
......@@ -288,7 +288,6 @@ WordSpace.setGameOverTimer = function()
{
this.isTimerOn = true;
WordSpace.gameOverCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.gameOver, 0, false);
console.log('Game over timer On');
}
}
......@@ -298,7 +297,6 @@ WordSpace.resetGameOverTimer = function()
{
this.isTimerOn = false;
WordSpace.gameOverCycle.currentCycle.paused = true;
console.log('Game over timer Off');
}
}
......@@ -334,9 +332,26 @@ WordSpace.findWord = function(wordText)
WordSpace.attackGauge.pauseCycle(true);
WordSpace.setPlayerTyping.add(wordText);
}
else
else // 오타 체크
{
WordSpace.wordGroup.forEach(function(element)
{
let inputWord = [], checkWord = [], diff = [];
let inputUnused = 0, checkUnused = 0;
for(let i = 0; i < wordText.lenRate; i++)
{
inputWord.push(WordReader.firstSound(wordText[i]));
inputWord.push(WordReader.middleSound(wordText[i]));
inputWord.push(WordReader.lastSound(wordText[i]));
}
for(let i = 0; i < element.lenRate; i++)
{
// 오타 체크
checkWord.push(WordReader.firstSound(element[i]));
checkWord.push(WordReader.middleSound(element[i]));
checkWord.push(WordReader.lastSound(element[i]));
}
});
}
}
......@@ -424,3 +439,40 @@ WordSpace.nameQueue =
this.shuffle();
}
}
WordSpace.testDistance = function(input, check) {
var inputWords = [], checkWords = []
for(let i = 0; i < input.length; i++)
{
inputWords.push(parseInt(((input[i].charCodeAt(0) - parseInt('0xac00',16)) /28) / 21) + parseInt('0x1100',16));
inputWords.push(parseInt(((input[i].charCodeAt(0)- parseInt('0xac00',16)) / 28) % 21) + parseInt('0x1161',16));
inputWords.push(parseInt((input[i].charCodeAt(0) - parseInt('0xac00',16)) % 28) + parseInt('0x11A8') -1);
}
for(let i = 0; i < check.length; i++)
{
checkWords.push(parseInt(((check[i].charCodeAt(0) - parseInt('0xac00',16)) /28) / 21) + parseInt('0x1100',16));
checkWords.push(parseInt(((check[i].charCodeAt(0)- parseInt('0xac00',16)) / 28) % 21) + parseInt('0x1161',16));
checkWords.push(parseInt((check[i].charCodeAt(0) - parseInt('0xac00',16)) % 28) + parseInt('0x11A8') -1);
}
var matrix = [];
// increment along the first column of each row
var i, j;
for(i = 0; i <= checkWords.length; i++)
matrix[i] = [i];
// increment each column in the first row
for(j = 0; j <= inputWords.length; j++)
matrix[0][j] = j;
// Fill in the rest of the matrix
for(i = 1; i <= checkWords.length; i++)
for(j = 1; j <= inputWords.length; j++){
if(checkWords[i-1] == inputWords[j-1]) matrix[i][j] = matrix[i-1][j-1];
else matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
Math.min(matrix[i][j-1] + 1, // insertion
matrix[i-1][j] + 1)); // deletion
}
console.log('edit distance is ' + matrix[checkWords.length][inputWords.length]);
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ var PlayerData = PlayerData || {};
PlayerData.idNum = -1; //플레이어 아이디, 고유 번호
PlayerData.nickname = '홍길동'; //플레이어 닉네임
// 현재 들어가있는 Game Room의 정보
var RoomData = RoomData || {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment