오늘의 목표
- 아침 코드카타
- 언리얼 멀티플레이 게임 강의 2, 3, 복습
- 언리얼 멀티플레이 게임 강의 4, 5 예습
배운 개념 정리
TCP와 UDP
UDP 프로토콜
UDP는 비연결성 프로토콜로, 연결 수립 과정이 없어 오버헤드가 적고 전송 속도가 빠르다.
UDP는 빠른 전송이 필요하고 일부 데이터 손실이 허용되는 상황에서 사용된다.
FPS 게임의 플레이어 위치 동기화는 UDP가 적합하다. 위치 정보는 초당 수십 번 업데이트되므로, 한두 개의 패킷이 손실되어도 다음 업데이트로 자연스럽게 보완된다. 실시간성이 중요하므로 재전송으로 인한 지연이 발생하는 TCP보다 빠른 UDP가 더 적합하다.
TCP의 3-way handshake
연결 수립을 위한 과정
1) 클라이언트가 SYN 패킷을 전송
2) 서버가 SYN-ACK 패킷으로 응답
3) 클라이언트가 ACK 패킷을 전송
요약
UDP는 빠른 전송
TCP는 보안 보장
코드카타
제 시간 내 풀기 실패
[내 풀이]
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int compare(const int* a, const int* b)
{
return *b - *a;
}
// score_len은 배열 score의 길이입니다.
int* solution(int k, int score[], size_t score_len) {
// return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
int* answer = (int*)malloc(sizeof(int) * score_len);
int answer_index = 0;
int* honor_rank = (int*)malloc((k + 1) * sizeof(int));
int score_index = 0;
for (; score_index < k; ++score_index)
{
honor_rank[score_index] = score[score_index];
printf("honor_rank[%d]: %d\n", score_index, honor_rank[score_index]);
}
qsort(honor_rank, k, sizeof(int), compare);
for (; answer_index < k; ++ answer_index)
{
answer[answer_index] = honor_rank[answer_index];
}
printf("[After sort]\n");
for (int i = 0; i < k; ++i)
{
printf("honor_rank[%d]: %d\n", i, honor_rank[i]);
}
for (size_t i = 0; i < score_len; ++i)
{
}
for (; score_index < (int)score_len; ++score_index)
{
if (honor_rank[k] < score[score_index])
{
}
}
for (; score_index < (int)score_len; ++score_index)
{
if (honor_rank[])
}
return answer;
}
개선 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int compare(const void* a, const void* b)
{
return *(int*)b - *(int*)a;
}
// score_len은 배열 score의 길이입니다.
int* solution(int k, int score[], size_t score_len) {
// return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
int* answer = (int*)malloc(sizeof(int) * score_len);
// 명예의 전당 배열
int* honor_rank = (int*)malloc(sizeof(int) * k);
int current_size = 0; // 현재 명예의 전당에 저장된 점수 개수
for (size_t i = 0; i < score_len; ++i)
{
// 자리가 비어 있을 때
if (current_size < k)
{
honor_rank[current_size++] = score[i];
}
else
{
// 꽉 찼을 때 명예의 전당 꼴지 점수와 비교
if (score[i] > honor_rank[k - 1])
{
honor_rank[k - 1] = score[i];
}
}
qsort(honor_rank, current_size, sizeof(int), compare);
// 명예의 전당 꼴지 값 저장
answer[i] = honor_rank[current_size - 1];
}
free (honor_rank);
return answer;
}
주요 개선점
처음 저장하는 k개의 점수를 따로 빼지 말고, 점수를 받아 저장하고 점수 내림차순대로 정렬하는 코드에 다 합쳐버리는 게 편하다.
직관적으로 우리가 생각하는 방식대로 코드를 짤 필요는 없음. 코드로 짰을 때 가장 효율적으로 계산할 수 있는 방식으로 만들면 됨!!
'Unreal5 공부 > TIL' 카테고리의 다른 글
| 2026/06/15 TIL (0) | 2026.06.15 |
|---|---|
| 2026/06/11 TIL (0) | 2026.06.11 |
| 2026/06/05 TIL (0) | 2026.06.05 |
| 2026/06/04 TIL (0) | 2026.06.05 |
| 2026/06/02 TIL (0) | 2026.06.02 |