Commit 0afbc7f8 authored by 18손재민's avatar 18손재민

오타 인식 구현 완료, 공격 단어가 이젠 공격자 이름만이 아니라 아이디까지 담음

parent 12e22ec6
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 = 1; GameServer.startCount = 3;
GameServer.currentPlayer = []; GameServer.currentPlayer = [];
GameServer.playingRoom = []; GameServer.playingRoom = [];
......
...@@ -114,19 +114,19 @@ class NormalWord extends WordObject ...@@ -114,19 +114,19 @@ class NormalWord extends WordObject
class AttackWord extends WordObject class AttackWord extends WordObject
{ {
constructor(text, _wordGrade, _attacker, isStrong) constructor(text, _wordGrade, _playerData, isStrong)
{ {
super(text); super(text);
this.wordGrade = _wordGrade; this.wordGrade = _wordGrade;
this.wordWeight = WordReader.getWordWeight(this.wordGrade); this.wordWeight = WordReader.getWordWeight(this.wordGrade);
if(WordReader.getWordTyping(_attacker) <= 9) if(WordReader.getWordTyping(_playerData.nickname) <= 9)
this.wordWeight += this.wordWeight * 0.2 * (WordReader.getWordTyping(PlayerData.nickname) - 9); this.wordWeight += this.wordWeight * 0.2 * (WordReader.getWordTyping(_playerData.nickname) - 9);
this.wordWeight *= isStrong ? 3 : 2; this.wordWeight *= isStrong ? 3 : 2;
this.attacker = _attacker; this.attacker = _playerData;
//서버 사용하게 되면 PlayerTyping을 피격자의 것으로 바꿔야 함 //서버 사용하게 되면 PlayerTyping을 피격자의 것으로 바꿔야 함
this.counterTime = WordSpace.gameTimer.now + 1000 * (this.wordTyping <= (5 - _wordGrade) * 2.5 ? this.wordTyping * (WordSpace.playerTyping / 60) * 2 : this.counterTime = WordSpace.gameTimer.now + 1000 * (this.wordTyping <= (5 - _wordGrade) * 2.5 ? this.wordTyping * (WordSpace.playerTyping / 60) * 2 :
((5 - _wordGrade) * 2.5 + (this.wordTyping - (5 - _wordGrade) * 2.5) * 3) * (WordSpace.playerTyping / 60) * 2); ((5 - _wordGrade) * 2.5 + (this.wordTyping - (5 - _wordGrade) * 2.5) * 3) * (WordSpace.playerTyping / 60) * 2);
console.log('Attack text : ' + text + ', Attacker : ' + this.attacker + ', Weight : ' + this.wordWeight); console.log('Attack text : ' + text + ', Attacker : ' + this.attacker.nickname + ', Weight : ' + this.wordWeight);
console.log('Counter time : ' + this.counterTime); console.log('Counter time : ' + this.counterTime);
} }
destroy() destroy()
......
...@@ -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()
...@@ -334,23 +334,24 @@ WordSpace.findWord = function(wordText) ...@@ -334,23 +334,24 @@ WordSpace.findWord = function(wordText)
} }
else // 오타 체크 else // 오타 체크
{ {
let minDist = 5, tempDist = 0;
let attackWords = [];
WordSpace.wordGroup.forEach(function(element) WordSpace.wordGroup.forEach(function(element)
{ {
let inputWord = [], checkWord = [], diff = []; if(element instanceof AttackWord)
let inputUnused = 0, checkUnused = 0;
for(let i = 0; i < wordText.lenRate; i++)
{ {
inputWord.push(WordReader.firstSound(wordText[i])); tempDist = WordSpace.getEditDistance(wordText, element.wordText);
inputWord.push(WordReader.middleSound(wordText[i])); attackWords.push(element);
inputWord.push(WordReader.lastSound(wordText[i])); if(tempDist <= minDist) minDist = tempDist;
} }
for(let i = 0; i < element.lenRate; i++) });
attackWords.forEach(function(element)
{
if(WordSpace.getEditDistance(wordText, element.wordText) == minDist)
{ {
checkWord.push(WordReader.firstSound(element[i])); //강호패 보내야 함
checkWord.push(WordReader.middleSound(element[i])); console.log('Attack word of ' + element.attacker.nickname + ' 오타임');
checkWord.push(WordReader.lastSound(element[i]));
} }
}); });
} }
} }
...@@ -384,23 +385,20 @@ WordSpace.attack = function(wordText, grade) ...@@ -384,23 +385,20 @@ WordSpace.attack = function(wordText, grade)
let attackData = let attackData =
{ {
roomNum: RoomData.roomNum, roomNum: RoomData.roomNum,
attacker: PlayerData.nickname, attacker: PlayerData,
target: element.ownerId, target: element.ownerId,
text: wordText, text: wordText,
grade: grade, grade: grade,
isStrong: element.isStrong isStrong: element.isStrong
} }
socket.emit('attack', attackData); socket.emit('attack', attackData);
//WordSpace.generateWord.Attack(WordSpace.gameSceneForTest, wordText, grade, PlayerData.nickname, element.isStrong);
}); });
//WordSpace.generateWord.Attack(WordSpace.gameSceneForTest, wordText, grade, PlayerData, false);
WordSpace.nameGroup = []; WordSpace.nameGroup = [];
WordSpace.attackGauge.resetValue(); WordSpace.attackGauge.resetValue();
WordSpace.setPlayerTyping.add(wordText); WordSpace.setPlayerTyping.add(wordText);
} }
else else WordSpace.attackGauge.cutValue(0.3);
{
WordSpace.attackGauge.cutValue(0.3);
}
Input.maxInput = 6; Input.maxInput = 6;
Input.attackMode = false; Input.attackMode = false;
WordSpace.attackGauge.pauseCycle(false); WordSpace.attackGauge.pauseCycle(false);
...@@ -424,8 +422,6 @@ WordSpace.nameQueue = ...@@ -424,8 +422,6 @@ WordSpace.nameQueue =
if(element.nickname != PlayerData.nickname && element.isAlive) if(element.nickname != PlayerData.nickname && element.isAlive)
WordSpace.nameQueue.queue.push(element); WordSpace.nameQueue.queue.push(element);
}); });
/*console.log(WordSpace.nameQueue.queue);
console.log(RoomData.aliveCount);*/
}, },
pop: function() pop: function()
{ {
...@@ -440,9 +436,7 @@ WordSpace.nameQueue = ...@@ -440,9 +436,7 @@ WordSpace.nameQueue =
} }
} }
WordSpace.getEditDistance = function(input, check) {
WordSpace.testDistance = function(input, check) {
var inputWords = [], checkWords = [] var inputWords = [], checkWords = []
for(let i = 0; i < input.length; i++) for(let i = 0; i < input.length; i++)
{ {
...@@ -457,22 +451,17 @@ WordSpace.testDistance = function(input, check) { ...@@ -457,22 +451,17 @@ WordSpace.testDistance = function(input, check) {
checkWords.push(parseInt((check[i].charCodeAt(0) - parseInt('0xac00',16)) % 28) + parseInt('0x11A8') -1); checkWords.push(parseInt((check[i].charCodeAt(0) - parseInt('0xac00',16)) % 28) + parseInt('0x11A8') -1);
} }
var matrix = []; var matrix = [];
// increment along the first column of each row
var i, j; var i, j;
for(i = 0; i <= checkWords.length; i++) for(i = 0; i <= checkWords.length; i++) // increment along the first column of each row
matrix[i] = [i]; matrix[i] = [i];
for(j = 0; j <= inputWords.length; j++) // increment each column in the first row
// increment each column in the first row
for(j = 0; j <= inputWords.length; j++)
matrix[0][j] = j; matrix[0][j] = j;
for(i = 1; i <= checkWords.length; i++) // Fill in the rest of the matrix
// Fill in the rest of the matrix
for(i = 1; i <= checkWords.length; i++)
for(j = 1; j <= inputWords.length; j++){ for(j = 1; j <= inputWords.length; j++){
if(checkWords[i-1] == inputWords[j-1]) matrix[i][j] = matrix[i-1][j-1]; 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 else matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
Math.min(matrix[i][j-1] + 1, // insertion Math.min(matrix[i][j-1] + 1, // insertion
matrix[i-1][j] + 1)); // deletion matrix[i-1][j] + 1)); // deletion
} }
console.log('edit distance is ' + matrix[checkWords.length][inputWords.length]); return matrix[checkWords.length][inputWords.length];
} }
\ No newline at end of file
...@@ -21,7 +21,6 @@ var PlayerData = PlayerData || {}; ...@@ -21,7 +21,6 @@ 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