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

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

parent ece8a72e
var GameServer = GameServer || {}; var GameServer = GameServer || {};
GameServer.Phase = {READY: 0, START: 1, MAIN: 2, MUSIC: 3}; GameServer.Phase = {READY: 0, START: 1, MAIN: 2, MUSIC: 3};
GameServer.startCount = 5; GameServer.startCount = 1;
GameServer.currentPlayer = []; GameServer.currentPlayer = [];
GameServer.playingRoom = []; GameServer.playingRoom = [];
......
...@@ -146,13 +146,13 @@ class AttackWord extends WordObject ...@@ -146,13 +146,13 @@ class AttackWord extends WordObject
class NameWord extends WordObject class NameWord extends WordObject
{ {
constructor(name, _isStrong = false) constructor(player, _isStrong = false)
{ {
super(name.nickname); super(player.nickname);
this.ownerId = name.id; this.ownerId = player.id;
this.wordWeight = 2; this.wordWeight = 2;
this.isStrong = _isStrong; 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() destroy()
{ {
......
var WordReader = WordReader || {}; var WordReader = WordReader || {};
//초성의 타수를 반환함 //초성의 타수를 반환함
function firstSound(charText) WordReader.firstSound = function(charText)
{ {
var r = parseInt(((charText.charCodeAt(0) - parseInt('0xac00',16)) /28) / 21); var r = parseInt(((charText.charCodeAt(0) - parseInt('0xac00',16)) /28) / 21);
//쌍자음일 경우 //쌍자음일 경우
...@@ -10,7 +10,7 @@ function firstSound(charText) ...@@ -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); var r = parseInt(((charText.charCodeAt(0)- parseInt('0xac00',16)) / 28) % 21);
//'ㅒ' 또는 'ㅖ'일 경우 //'ㅒ' 또는 'ㅖ'일 경우
...@@ -21,7 +21,7 @@ function middleSound(charText) ...@@ -21,7 +21,7 @@ function middleSound(charText)
} }
//종성의 타수를 반환함 //종성의 타수를 반환함
function lastSound(charText) WordReader.lastSound = function(charText)
{ {
var r = parseInt((charText.charCodeAt(0) - parseInt('0xac00',16)) % 28); var r = parseInt((charText.charCodeAt(0) - parseInt('0xac00',16)) % 28);
//쌍자음일 경우 //쌍자음일 경우
...@@ -40,7 +40,7 @@ WordReader.getWordTyping = function(stringText) ...@@ -40,7 +40,7 @@ WordReader.getWordTyping = function(stringText)
for(var i = 0; i < stringText.length; i++) for(var i = 0; i < stringText.length; i++)
{ {
if(stringText.charCodeAt(i) < parseInt('0xac00',16) || stringText.charCodeAt(i) > parseInt('0xd7af',16)) return -1; 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; return temp;
} }
......
...@@ -70,7 +70,7 @@ WordSpace.gameOverCycle = new Cycle(gameOver); ...@@ -70,7 +70,7 @@ WordSpace.gameOverCycle = new Cycle(gameOver);
//호패 생성 사이클 //호패 생성 사이클
WordSpace.nameCycle = new Cycle(function() WordSpace.nameCycle = new Cycle(function()
{ {
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false); //WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
}); });
//이건 뭐지 //이건 뭐지
WordSpace.varAdjustCycle = new Cycle(function() WordSpace.varAdjustCycle = new Cycle(function()
...@@ -288,7 +288,6 @@ WordSpace.setGameOverTimer = function() ...@@ -288,7 +288,6 @@ WordSpace.setGameOverTimer = function()
{ {
this.isTimerOn = true; this.isTimerOn = true;
WordSpace.gameOverCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.gameOver, 0, false); WordSpace.gameOverCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.gameOver, 0, false);
console.log('Game over timer On');
} }
} }
...@@ -298,7 +297,6 @@ WordSpace.resetGameOverTimer = function() ...@@ -298,7 +297,6 @@ WordSpace.resetGameOverTimer = function()
{ {
this.isTimerOn = false; this.isTimerOn = false;
WordSpace.gameOverCycle.currentCycle.paused = true; WordSpace.gameOverCycle.currentCycle.paused = true;
console.log('Game over timer Off');
} }
} }
...@@ -334,9 +332,26 @@ WordSpace.findWord = function(wordText) ...@@ -334,9 +332,26 @@ WordSpace.findWord = function(wordText)
WordSpace.attackGauge.pauseCycle(true); WordSpace.attackGauge.pauseCycle(true);
WordSpace.setPlayerTyping.add(wordText); 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]));
}
});
} }
} }
...@@ -423,4 +438,41 @@ WordSpace.nameQueue = ...@@ -423,4 +438,41 @@ WordSpace.nameQueue =
this.shuffle(); this.shuffle();
this.shuffle(); 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 || {}; ...@@ -21,6 +21,7 @@ var PlayerData = PlayerData || {};
PlayerData.idNum = -1; //플레이어 아이디, 고유 번호 PlayerData.idNum = -1; //플레이어 아이디, 고유 번호
PlayerData.nickname = '홍길동'; //플레이어 닉네임 PlayerData.nickname = '홍길동'; //플레이어 닉네임
// 현재 들어가있는 Game Room의 정보 // 현재 들어가있는 Game Room의 정보
var RoomData = RoomData || {}; 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